Introduction
When we open MessageBox in a WPF application, it looks are very similar to that of a Window Form. We cannot inherits or apply style to MessageBox. Using MessageBox in a WPF application with a rich user interface can look bad. So in this article we will create our own WPFMessageBox with rich user interface.
Using the code
WPFMessageBox is very similar to MessageBox in WPF with added functionality and rich user interface. We can apply two different skin to WPFMessageBox just by setting Skin property.
WPFMessageBox with Black Skin
WPFMessageBox with Blue Skin
Code to apply Black Skin and Blue Skin to WPFMessageBox is as below
'Code to apply Black Skin WpfMessageBox.Skin = DisplaySkin.Black 'Code to apply Blue Skin WpfMessageBox.Skin = DisplaySkin.Blue
Just like MessageBox, WPFMessageBox also has Show() method with various overloads to set caption, text, icon, buttons and default result.
Various overloaded functions for WPFMessageBox are shown in following code.
Function Show(ByVal text As String) As WpfMessageBoxResult Function Show(ByVal text As String, ByVal caption As String) As WpfMessageBoxResult Function Show(ByVal text As String, ByVal caption As String, ByVal button As WpfMessageBoxButton) As WpfMessageBoxResult Function Show(ByVal text As String, ByVal caption As String, ByVal button As WpfMessageBoxButton, ByVal icon As WpfMessageBoxImage) As WpfMessageBoxResult Function Show(ByVal text As String, ByVal caption As String, ByVal button As WpfMessageBoxButton, ByVal icon As WpfMessageBoxImage, ByVal defaultResult As WpfMessageBoxResult) As WpfMessageBoxResult
All these overload functions are shared. So we can use them without creating their object.
Above example will show WPFMessageBox with “Message box with a text and Caption” as text and “WPF Message Box” as caption.
Above example will show “Message with Yes and No” as text, “WPF Message Box” as caption and will contain Yes and No button.
Code for WPFMessageBox.Show have similar overload parameters to MessageBox.Show with great user interface. So one familiar to MessageBox can easily use WPFMessageBox
You can download the code from below link
Download Source Code