MessageBox
Displays a message box that has a message and that returns a result.Buttons
Icons
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.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.
<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.
---