MaterialMessageBox-x86

Material Message Box for WPF apps.


Keywords
wpf, messagebox, materialdesign, material-ui, desktop, material-design
License
WTFPL
Install
Install-Package MaterialMessageBox-x86 -Version 1.0.1

Documentation

MaterialMessageBox

Library on .NET Core 3.0 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.3.0+) or in VSCode (1.38.1+) with omnisharp-vscode extension (1.21.3+).

Icon

Build statusActions Status

Current version

Get latest version on releases page: Release, or on NuGet:

Windows x86: NuGet

Windows x64: 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.

Requirements

  • Windows 7 or newer;
  • .NET Core 3.0;

Dependencies

API

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.

MaterialMessageBoxWindow

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();

MaterialMessageBoxUserControl

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);

Screenshots

Usual Window

UsualWindow

Usual UserControl

UsualUserControl

Custom Window

CustomWindow

Custom UserControl

CustomUserControl

Error Window

ErrorWindow

Error UserControl

ErrorUserControl

Warning Window

WarningWindow

Warning UserControl

WarningUserControl

Contributing

Feel free to contribute, make forks, change some code, add issues, etc.