Library on .NET Core 3.1 implementing material design message box in WPF.
Original idea and some code is written by denpalrius, but I’ve changed some major stuff and decided to make it different repository. Text for message boxes in Demo is taken from here. Icon is taken from here.
You can build project in VS2019 (16.4.1+) or in VSCode (1.40.2+) with omnisharp-vscode extension (1.21.8+).
Get latest version on releases page: , or on NuGet:
Information about changes since previous releases can be found in changelog. This project supports SemVer 2.0.0 (template is {MAJOR}.{MINOR}.{PATCH}.{BUILD}
).
Previous versions can be found on releases and branches pages.
- Windows 7 or newer;
- .NET Core 3.1;
- MaterialDesignThemes – 3.0.1;
- MaterialDesignColors – 1.2.2;
Library implements two different kinds of message boxes: Window and UserControl. See screenshots below to see the difference in design.
To use API, add using MaterialMessageBox
directive to your classes.
Contains three slightly different static Show(...)
methods:
public static MessageBoxResult Show(string message, bool isCancelButtonVisible = false, bool isRightToLeft = false) {...}
public static MessageBoxResult ShowError(string message, bool isCancelButtonVisible = false, bool isRightToLeft = false) {...}
public static MessageBoxResult ShowWarning(string message, bool isCancelButtonVisible = false, bool isRightToLeft = false) {...}
Which you can call in your code like this:
MaterialMessageBoxWindow.Show(MessageBoxMessage);
MaterialMessageBoxWindow.ShowError(MessageBoxMessage, true, true);
MaterialMessageBoxWindow.ShowWarning(MessageBoxMessage, true);
But also you can create MaterialMessageBoxWindow
object and rewrite some stuff for yourself:
MaterialMessageBoxWindow materialMessageBoxWindow = new MaterialMessageBoxWindow
{
MessageTextBlock = { Text = MessageBoxMessage, Foreground = Brushes.Yellow },
CopyToClipboardButton = { Visibility = Visibility.Hidden },
OkButton = { Content = "Good", Foreground = Brushes.Yellow, Background = Brushes.LightCoral},
CancelButton = { Content = "Bad", Foreground = Brushes.Blue, Background = Brushes.LightBlue},
BordersGrid = { Background = Brushes.IndianRed },
MainGrid = { Background = Brushes.Red }, BorderBrush = Brushes.DarkRed,
BorderThickness = new Thickness(4, 4, 4, 4)
};
materialMessageBoxWindow.ShowDialog();
To use this, you must specify DialogHost
in your .xaml
file.
Code is mostly the same, as in MaterialMessageBoxWindow
, but there’s also implemented both Async
and non-Async
methods:
public static async ValueTask<MessageBoxResult> ShowAsync(string message, bool isCancelButtonVisible = false, bool isRightToLeft = false) {...}
public static async ValueTask<MessageBoxResult> ShowErrorAsync(string message, bool isCancelButtonVisible = false, bool isRightToLeft = false) {...}
public static async ValueTask<MessageBoxResult> ShowWarningAsync(string message, bool isCancelButtonVisible = false, bool isRightToLeft = false) {...}
public static MessageBoxResult Show(string message, bool isCancelButtonVisible = false, bool isRightToLeft = false) {...}
public static MessageBoxResult ShowError(string message, bool isCancelButtonVisible = false, bool isRightToLeft = false) {...}
public static MessageBoxResult ShowWarning(string message, bool isCancelButtonVisible = false, bool isRightToLeft = false) {...}
Ways to call it are pretty much the same (don’t forget to make your methods async
and use ConfigureAwait
):
await MaterialMessageBoxUserControl.ShowAsync(MessageBoxMessage);
await MaterialMessageBoxUserControl.ShowErrorAsync(MessageBoxMessage, true, true);
await MaterialMessageBoxUserControl.ShowWarningAsync(MessageBoxMessage, true)
And of course you can also create MaterialMessageBoxUserControl
object, but note, that there’s a bit different way to call Show()
method:
MaterialMessageBoxUserControl materialMessageBoxUserControl = new MaterialMessageBoxUserControl
{
MessageTextBlock = { Text = MessageBoxMessage, Foreground = Brushes.Yellow },
CopyToClipboardButton = { Visibility = Visibility.Hidden },
OkButton = { Content = "Good", Foreground = Brushes.Yellow, Background = Brushes.LightCoral },
CancelButton = { Content = "Bad", Foreground = Brushes.Blue, Background = Brushes.LightBlue },
BordersGrid = { Background = Brushes.IndianRed },
MainGrid = { Background = Brushes.Red },
BorderBrush = Brushes.DarkRed,
BorderThickness = new Thickness(4, 4, 4, 4)
};
await DialogHost.Show(materialMessageBoxUserControl);
Usual Window
Usual UserControl
Custom Window
Custom UserControl
Error Window
Error UserControl
Warning Window
Warning UserControl
Feel free to contribute, make forks, change some code, add issues, etc.