xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MessageBoxSample" Height="300" Width="500">
MessageBoxText
Caption
OK
OKCancel
YesNo
YesNoCancel
Asterisk
Error
Exclamation
Hand
Information
None
Question
Stop
Warning
Cancel
No
None
OK
Yes
DefaultDesktopOnly
None
RightAlign
RtlReading
ServiceNotification
Ready
//File:Window.xaml.cs
using System;
using System.Windows;
namespace MessageBoxSample
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
void showMessageBoxButton_Click(object sender, RoutedEventArgs e)
{
Window owner = ((bool)ownerCheckBox.IsChecked ? this : null);
string messageBoxText = this.messageBoxText.Text;
string caption = this.caption.Text;
MessageBoxButton button = (MessageBoxButton)Enum.Parse(typeof(MessageBoxButton), this.buttonComboBox.Text);
MessageBoxImage icon = (MessageBoxImage)Enum.Parse(typeof(MessageBoxImage), this.imageComboBox.Text);
MessageBoxResult defaultResult = (MessageBoxResult)Enum.Parse(typeof(MessageBoxResult), this.defaultResultComboBox.Text);
MessageBoxOptions options = (MessageBoxOptions)Enum.Parse(typeof(MessageBoxOptions), this.optionsComboBox.Text);
MessageBoxResult result;
if (owner == null)
{
result = MessageBox.Show(messageBoxText, caption, button, icon, defaultResult, options);
}
else
{
result = MessageBox.Show(owner, messageBoxText, caption, button, icon, defaultResult, options);
}
resultTextBlock.Text = "Result = " + result.ToString();
}
}
}