MessageBox

Displays a message box that has a message and that returns a result.

Buttons
messagebox_buttons.jpg

Icons
messagebox_icons.jpg

Usage

The MessageBox mimics the behavior of the System.Windows.MessageBox closely. You use similar syntax to create and show a message box.

      MessageBoxResult result =  Microsoft.Windows.Controls.MessageBox.Show("Hello world!", "Extended WPF ToolKit MessageBox", MessageBoxButton.OK, MessageBoxImage.Question);
      MessageBoxResult result =  Microsoft.Windows.Controls.MessageBox.Show("Hello world!", "Extended WPF ToolKit MessageBox", MessageBoxButton.OK);
      MessageBoxResult result =  Microsoft.Windows.Controls.MessageBox.Show("Hello world!", "Extended WPF ToolKit MessageBox");
      MessageBoxResult result =  Microsoft.Windows.Controls.MessageBox.Show("Hello world!");


Style Guide

You can style the MessageBox to fit the theme of your application by using a few of the MessageBox's properties. The following image depicts what properties modify which parts of the MessageBox control.
messagebox_style_guide.jpg

Property Description
CancelButtonContent Sets the content of the Cancel button
Caption Gets or sets the caption of the message box.
CaptionForeground Changes the font color of the caption
CloseButtonStyle Changes the style of the close button. You can also retemplate the close button using this style
Container Gets or sets the container which contains the MessageBox.
DragWidget Gets or sets the drag widget thumb.
ImageSource Gets or sets the ImageSource.
NoButtonContent Sets the content of the No button
OkButtonContent Sets the content of the OK button
Text Gets or sets the text of the message box.
WindowBackground Changes the background color of the MessageBox window
WindowBorderBrush Changes the color of the outer border of the MessageBox
WindowOpacity Changes the opacity of the MessageBox, but does not effect the close button or the message text area
YesButtonContent Sets the content of the Yes button


Example
You can style all instances of your MessageBox control by placing the style definition markup inside your App.xaml file under the resources section. To create the following ugly style requires the following markup.

style_example.jpg

        <SolidColorBrush x:Key="MyButtonHoverBrush" Color="YellowGreen" />
        <SolidColorBrush x:Key="MyButtonPressedBrush" Color="Maroon" />
        
        <Style x:Key="MyCloseButtonStyle" TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="Background" Storyboard.TargetProperty="(Border.Background)">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{StaticResource MyButtonHoverBrush}"></DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="Background" Storyboard.TargetProperty="(Border.Background)">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{StaticResource MyButtonPressedBrush}"></DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border x:Name="Background" CornerRadius="0,0,2,0" Background="Green">
                                <Border Margin="1,0,1,1" BorderBrush="#59FFFFFF" BorderThickness="1" CornerRadius="0,0,1,0"/>
                            </Border>
                            <ContentPresenter x:Name="contentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
                            <Path x:Name="path" Fill="White" Margin="0,0,0,1" Visibility="Collapsed"
	                Height="6"
		Width="7"
		Stretch="Fill"
		Opacity="1"
		Data="M 2,6 C2,6 3,6 3,6 3,6 3,5 3,5 3,5 4,5 4,5 4,5 4,6 4,6 4,6 5,6 5,6 5,6 7,6 7,6 7,6 7,5 7,5 7,5 6,5 6,5 6,5 6,4 6,4 6,4 5,4 5,4 5,4 5,2 5,2 5,2 6,2 6,2 6,2 6,1 6,1 6,1 7,1 7,1 7,1 7,0 7,0 7,0 5,0 5,0 5,0 4,0 4,0 4,0 4,1 4,1 4,1 3,1 3,1 3,1 3,0 3,0 3,0 2,0 2,0 2,0 0,0 0,0 0,0 0,1 0,1 0,1 1,1 1,1 1,1 1,2 1,2 1,2 2,2 2,2 2,2 2,4 2,4 2,4 1,4 1,4 1,4 1,5 1,5 1,5 0,5 0,5 0,5 0,6 0,6 0,6 2,6 2,6 z"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        
        <Style TargetType="{x:Type toolkit:MessageBox}">
            <Setter Property="Background" Value="Aquamarine" />
            <Setter Property="BorderBrush" Value="Red" />
            <Setter Property="CaptionForeground" Value="Orange" />
            <Setter Property="WindowBorderBrush" Value="Blue" />
            <Setter Property="WindowBackground" Value="Green" />
            <Setter Property="WindowOpacity" Value="0.3" />
            <Setter Property="Foreground" Value="Purple"/>
            <Setter Property="CloseButtonStyle" Value="{StaticResource MyCloseButtonStyle}"/>
        </Style>



Get 50+ awesome WPF controls in the Plus Edition.
---

Last edited May 9 at 8:48 PM by Kosmatos, version 36

Comments

Dev_Matthias Feb 15 at 12:28 PM 
Thank you very much!
When is the 2.0 planned to release? i hope ASAP :)

BoucherS Feb 15 at 11:59 AM 
MessageBoxes will work in XBAP in the version 2.0 of the toolkit.

Dev_Matthias Feb 15 at 10:13 AM 
I have a problem with MessageBox while using it a XBAP application. i get an error when the messagebox must show a dialog:
System.InvalidOperationException: Cannot perform this operation when hosted in browser.
at MS.Internal.AppModel.RootBrowserWindow.VerifyApiSupported()
It would be great if its supported in XBAP!! :)

Konstantinos Nov 17, 2012 at 11:31 PM 
"Is there a way to use this "non-client area replacement" (I think it's called a chrome) in a custom Window?"

I just saw you have the class ChildWindow.
I guess nothing yet for windows with minimize/maximize buttons, etc, ah?

Konstantinos Nov 17, 2012 at 11:14 PM 
Nice tools you've built here!

Is there a way to use this "non-client area replacement" (I think it's called a chrome) in a custom Window?
I didn't see any documentation on that.

And you could also make the MyCloseButtonStyle above set Focusable to False.

Also, in your DateTimePicker you could draw the drop-down button arrow using a path. It seems digitized when you use a scale transform on it. Also I haven't found a way to change the content of the button that says 'Advanced' on the DateTimePicker (in .NET code at least - haven't tried with ControlTemplates). I use version 1.6 (I think). Perhaps you've changed some things since then.

xqandpan Nov 7, 2012 at 1:23 AM 
I want to customize the MessageBoxImage, how can I do it?

BoucherS Oct 11, 2012 at 8:14 PM 
In v1.8, there are new Properties : OkButtonStyle, CancelButtonStyle, YesButtonStyle and NoButtonStyle that let you specify the style of each button.

zhaolq85 Jun 18, 2012 at 3:07 AM 
I want to modify the style of OK and Cancle button .But I don't how?