Skip to content

It looks like ContentDialog now. #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions ModernWpf.MessageBox.Test/App.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Application x:Class="ModernWpfMessageBox.Test.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ModernWpfMessageBox.Test"
xmlns:ui="http://schemas.modernwpf.com/2019"
ShutdownMode="OnLastWindowClose">
<Application
x:Class="ModernWpfMessageBox.Test.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ModernWpfMessageBox.Test"
xmlns:ui="http://schemas.modernwpf.com/2019"
ShutdownMode="OnLastWindowClose">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down
39 changes: 21 additions & 18 deletions ModernWpf.MessageBox.Test/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
using System.Windows;
using ModernWpf;
using ModernWpf;
using ModernWpf.Controls;
using System.Windows;

namespace ModernWpfMessageBox.Test {
public partial class App : Application {
protected override void OnStartup(StartupEventArgs e) {
namespace ModernWpfMessageBox.Test
{
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

var title = "Some title";
var message = "This is a looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong test text!";
string title = "Some title";
string message = "This is a looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong test text!";

// MessageBox.Show(message, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
// MessageBox.Show("adawdawda", title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
System.Windows.MessageBox.Show(message, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
System.Windows.MessageBox.Show("adawdawda", title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
ShutdownMode = ShutdownMode.OnExplicitShutdown;
// ModernWpf.MessageBox.Show("This is a test text!", "Some title", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
// ModernWpf.MessageBox.Show(message, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
ModernWpf.MessageBox.Show("redadwada", null, MessageBoxButton.OK, Symbol.Admin);
ModernWpf.MessageBox.Show("redadwada", null, MessageBoxButton.OK, SymbolGlyph.Airplane);
ModernWpf.MessageBox.Show("redadwada", null, MessageBoxButton.OK, SymbolGlyph.Airplane, MessageBoxResult.OK);
ModernWpf.MessageBox.ShowAsync(message, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question).GetAwaiter().GetResult();
ModernWpf.MessageBox.ShowAsync(message, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Hand, MessageBoxResult.Cancel).GetAwaiter().GetResult();
ModernWpf.MessageBox.EnableLocalization = false;
ModernWpf.MessageBox.ShowAsync("Press Alt and you should see underscores!", null, MessageBoxButton.YesNoCancel, MessageBoxImage.Hand).GetAwaiter().GetResult();
ModernWpf.Controls.MessageBox.Show("This is a test text!", "Some title", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
ModernWpf.Controls.MessageBox.Show(message, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
ModernWpf.Controls.MessageBox.Show("redadwada", null, MessageBoxButton.OK, ((char)Symbol.Admin).ToString());
ModernWpf.Controls.MessageBox.Show("redadwada", null, MessageBoxButton.OK, SymbolGlyph.Airplane);
ModernWpf.Controls.MessageBox.Show("redadwada", null, MessageBoxButton.OK, SymbolGlyph.Airplane, MessageBoxResult.OK);
ModernWpf.Controls.MessageBox.ShowAsync(message, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question).GetAwaiter().GetResult();
ModernWpf.Controls.MessageBox.ShowAsync(message, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Hand, MessageBoxResult.Cancel).GetAwaiter().GetResult();
ModernWpf.Controls.MessageBox.EnableLocalization = false;
ModernWpf.Controls.MessageBox.ShowAsync("Press Alt and you should see underscores!", null, MessageBoxButton.YesNoCancel, MessageBoxImage.Hand).GetAwaiter().GetResult();
Shutdown();
}
}
Expand Down
3 changes: 1 addition & 2 deletions ModernWpf.MessageBox.Test/ModernWpf.MessageBox.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net45;net462;netcoreapp3.0;net5.0-windows10.0.18362</TargetFrameworks>
<TargetFramework>net6.0-windows10.0.18362.0</TargetFramework>
<UseWPF>True</UseWPF>
<StartupObject></StartupObject>
</PropertyGroup>

<ItemGroup>
Expand Down
217 changes: 217 additions & 0 deletions ModernWpf.MessageBox/Extensions/DWMAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace MS.Win32
{
/// <summary>
/// Used by Desktop Window Manager (DWM)
/// </summary>
internal static class DWMAPI
{
/// <summary>
/// DWMWINDOWATTRIBUTE enumeration. (dwmapi.h)
/// <para><see href="https://github.com/electron/electron/issues/29937"/></para>
/// </summary>
[Flags]
public enum DWMWINDOWATTRIBUTE : uint
{
/// <summary>
/// Enables or forcibly disables DWM transitions. The pvAttribute parameter points to a value of type BOOL. TRUE to disable transitions, or FALSE to enable transitions.
/// </summary>
DWMWA_TRANSITIONS_FORCEDISABLED = 3,

/// <summary>
/// Enables content rendered in the non-client area to be visible on the frame drawn by DWM.
/// </summary>
DWMWA_ALLOW_NCPAINT = 4,

/// <summary>
/// Retrieves the bounds of the caption button area in the window-relative space.
/// </summary>
DWMWA_CAPTION_BUTTON_BOUNDS = 5,

/// <summary>
/// Forces the window to display an iconic thumbnail or peek representation (a static bitmap), even if a live or snapshot representation of the window is available.
/// </summary>
DWMWA_FORCE_ICONIC_REPRESENTATION = 7,

/// <summary>
/// Cloaks the window such that it is not visible to the user.
/// </summary>
DWMWA_CLOAK = 13,

/// <summary>
/// If the window is cloaked, provides one of the following values explaining why.
/// </summary>
DWMWA_CLOAKED = 14,

/// <summary>
/// Freeze the window's thumbnail image with its current visuals. Do no further live updates on the thumbnail image to match the window's contents.
/// </summary>
DWMWA_FREEZE_REPRESENTATION = 15,

/// <summary>
/// Allows a window to either use the accent color, or dark, according to the user Color Mode preferences.
/// </summary>
DWMWA_USE_IMMERSIVE_DARK_MODE_OLD = 19,

/// <summary>
/// Allows a window to either use the accent color, or dark, according to the user Color Mode preferences.
/// </summary>
DWMWA_USE_IMMERSIVE_DARK_MODE = 20,

/// <summary>
/// Controls the policy that rounds top-level window corners.
/// <para>Windows 11 and above.</para>
/// </summary>
DWMWA_WINDOW_CORNER_PREFERENCE = 33,

/// <summary>
/// The color of the thin border around a top-level window.
/// </summary>
DWMWA_BORDER_COLOR = 34,

/// <summary>
/// The color of the caption.
/// <para>Windows 11 and above.</para>
/// </summary>
DWMWA_CAPTION_COLOR = 35,

/// <summary>
/// The color of the caption text.
/// <para>Windows 11 and above.</para>
/// </summary>
DWMWA_TEXT_COLOR = 36,

/// <summary>
/// Width of the visible border around a thick frame window.
/// <para>Windows 11 and above.</para>
/// </summary>
DWMWA_VISIBLE_FRAME_BORDER_THICKNESS = 37,

/// <summary>
/// Allows to enter a value from 0 to 4 deciding on the imposed backdrop effect.
/// </summary>
DWMWA_SYSTEMBACKDROP_TYPE = 38,

/// <summary>
/// Indicates whether the window should use the Mica effect.
/// <para>Windows 11 and above.</para>
/// </summary>
DWMWA_MICA_EFFECT = 1029
}

/// <summary>
/// Collection of backdrop types.
/// </summary>
[Flags]
public enum DWMSBT : uint
{
/// <summary>
/// Automatically selects backdrop effect.
/// </summary>
DWMSBT_AUTO = 0,

/// <summary>
/// Turns off the backdrop effect.
/// </summary>
DWMSBT_DISABLE = 1,

/// <summary>
/// Sets Mica effect with generated wallpaper tint.
/// </summary>
DWMSBT_MAINWINDOW = 2,

/// <summary>
/// Sets acrlic effect.
/// </summary>
DWMSBT_TRANSIENTWINDOW = 3,

/// <summary>
/// Sets blurred wallpaper effect, like Mica without tint.
/// </summary>
DWMSBT_TABBEDWINDOW = 4
}

/// <summary>
/// Abstraction of pointer to an object containing the attribute value to set. The type of the value set depends on the value of the dwAttribute parameter.
/// The DWMWINDOWATTRIBUTE enumeration topic indicates, in the row for each flag, what type of value you should pass a pointer to in the pvAttribute parameter.
/// </summary>
public enum PvAttribute
{
/// <summary>
/// Object containing the <see langowrd="false"/> attribute value to set in dwmapi.h.
/// </summary>
Disable = 0x00,

/// <summary>
/// Object containing the <see langowrd="true"/> attribute value to set in dwmapi.h.
/// </summary>
Enable = 0x01
}

/// <summary>
/// Represents the current DWM color accent settings.
/// </summary>
public struct DWMCOLORIZATIONPARAMS
{
/// <summary>
/// ColorizationColor
/// </summary>
public uint clrColor;

/// <summary>
/// ColorizationAfterglow.
/// </summary>
public uint clrAfterGlow;

/// <summary>
/// ColorizationColorBalance.
/// </summary>
public uint nIntensity;

/// <summary>
/// ColorizationAfterglowBalance.
/// </summary>
public uint clrAfterGlowBalance;

/// <summary>
/// ColorizationBlurBalance.
/// </summary>
public uint clrBlurBalance;

/// <summary>
/// ColorizationGlassReflectionIntensity.
/// </summary>
public uint clrGlassReflectionIntensity;

/// <summary>
/// ColorizationOpaqueBlend.
/// </summary>
public bool fOpaque;
}

/// <summary>
/// Sets the value of Desktop Window Manager (DWM) non-client rendering attributes for a window.
/// </summary>
/// <param name="hWnd">The handle to the window for which the attribute value is to be set.</param>
/// <param name="dwAttribute">A flag describing which value to set, specified as a value of the DWMWINDOWATTRIBUTE enumeration.</param>
/// <param name="pvAttribute">A pointer to an object containing the attribute value to set.</param>
/// <param name="cbAttribute">The size, in bytes, of the attribute value being set via the <c>pvAttribute</c> parameter.</param>
/// <returns>If the function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</returns>
[DllImport("dwmapi.dll")]
public static extern int DwmSetWindowAttribute(IntPtr hWnd, DWMWINDOWATTRIBUTE dwAttribute, ref int pvAttribute,
int cbAttribute);

/// <summary>
/// The feature is not included in the Microsoft documentation. Reads Desktop Window Manager (DWM) color information.
/// </summary>
/// <param name="dwParameters">A pointer to a reference value that will hold the color information.</param>
[DllImport("dwmapi.dll", EntryPoint = "#127", PreserveSig = false, CharSet = CharSet.Unicode)]
public static extern void DwmGetColorizationParameters(out DWMCOLORIZATIONPARAMS dwParameters);
}
}
12 changes: 8 additions & 4 deletions ModernWpf.MessageBox/Extensions/MessageBoxImageExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System;
using System.Windows;

namespace ModernWpf.Extensions {
internal static class MessageBoxImageExtensions {
public static SymbolGlyph ToSymbol(this MessageBoxImage image) {
return image switch {
namespace ModernWpf.Extensions
{
internal static class MessageBoxImageExtensions
{
public static SymbolGlyph ToSymbol(this MessageBoxImage image)
{
return image switch
{
MessageBoxImage.Error => SymbolGlyph.Error,
MessageBoxImage.Information => SymbolGlyph.Info,
MessageBoxImage.Warning => SymbolGlyph.Warning,
Expand Down
49 changes: 49 additions & 0 deletions ModernWpf.MessageBox/Extensions/OSVersionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace ModernWpf
{
internal static class OSVersionHelper
{
public static readonly Version OSVersion = GetOSVersion();

public static bool IsWindowsNT { get; } = Environment.OSVersion.Platform == PlatformID.Win32NT;

public static bool IsWindowsVistaOrGreater { get; } = IsWindowsNT && OSVersion >= new Version(6, 0);

public static bool IsWindows7OrGreater { get; } = IsWindowsNT && OSVersion >= new Version(6, 1);

public static bool IsWindows8OrGreater { get; } = IsWindowsNT && OSVersion >= new Version(6, 2);

public static bool IsWindows81OrGreater { get; } = IsWindowsNT && OSVersion >= new Version(6, 2);

public static bool IsWindows10OrGreater { get; } = IsWindowsNT && OSVersion >= new Version(10, 0);

public static bool IsWindows11OrGreater { get; } = IsWindowsNT && OSVersion >= new Version(10, 0, 21996);

private static Version GetOSVersion()
{
var osv = new RTL_OSVERSIONINFOEX();
osv.dwOSVersionInfoSize = (uint)Marshal.SizeOf(osv);
int ret = RtlGetVersion(out osv);
Debug.Assert(ret == 0);
return new Version((int)osv.dwMajorVersion, (int)osv.dwMinorVersion, (int)osv.dwBuildNumber);
}

[DllImport("ntdll.dll")]
private static extern int RtlGetVersion(out RTL_OSVERSIONINFOEX lpVersionInformation);

[StructLayout(LayoutKind.Sequential)]
private struct RTL_OSVERSIONINFOEX
{
internal uint dwOSVersionInfoSize;
internal uint dwMajorVersion;
internal uint dwMinorVersion;
internal uint dwBuildNumber;
internal uint dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
internal string szCSDVersion;
}
}
}
6 changes: 4 additions & 2 deletions ModernWpf.MessageBox/Extensions/SymbolExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using ModernWpf.Controls;

namespace ModernWpf.Extensions {
internal static class SymbolExtensions {
namespace ModernWpf.Extensions
{
internal static class SymbolExtensions
{
public static string ToGlyph(this Symbol symbol) =>
char.ConvertFromUtf32((int)symbol);
}
Expand Down
6 changes: 4 additions & 2 deletions ModernWpf.MessageBox/Extensions/SymbolGlyphExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace ModernWpf.Extensions {
internal static class SymbolGlyphExtensions {
namespace ModernWpf.Extensions
{
internal static class SymbolGlyphExtensions
{
public static string ToGlyph(this SymbolGlyph symbol) =>
char.ConvertFromUtf32((int)symbol);
}
Expand Down
Loading