Export (0) Print
Expand All
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

MessageBox.Show Method (String, String, MessageBoxButton)

July 28, 2014

Displays a message box that contains the specified text, title bar caption, and response buttons.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

public static MessageBoxResult Show(
	string messageBoxText,
	string caption,
	MessageBoxButton button
)

Parameters

messageBoxText
Type: System.String
The message to display.
caption
Type: System.String
The title of the message box.
button
Type: System.Windows.MessageBoxButton
A value that indicates the button or buttons to display.

Return Value

Type: System.Windows.MessageBoxResult
A value that indicates the user's response to the message.

ExceptionCondition
ArgumentNullException

messageBoxText is null.

-or-

caption is null.

ArgumentException

button is not a valid MessageBoxButton value.

Windows 8 Windows Phone 8: In Windows Phone 8 if you call Show method from the app Activated or Launching event handlers an InvalidOperationException is thrown with the message Error Displaying MessageBox. Alternatively, you should call the Show method from the Page.OnNavigatedTo(NavigationEventArgs) method.

In addition, in Windows Phone 8, if you call Show in OnBackKeyPress(CancelEventArgs) or a handler for the BackKeyPress event, the app will exit. You can work around this by calling Show on a different thread described in the following steps.

  1. Override BackKeyPress or create a handler for the BackKeyPress event,

  2. Set the Cancel to true to cancel the back key press action

  3. Dispatch a method that shows the MessageBox

  4. If the user chooses to leave the app, call Terminate(), otherwise do nothing.

The message box is modal, which means that the user must tap a button to dismiss the message.

If the button parameter is OK, then the return value is OK in all cases.

If the button parameter is OKCancel, then the return value is OK only when the user has tapped the OK button. Otherwise, the return value is Cancel.

The following example code demonstrates how to use this method.


MessageBoxResult result = 
    MessageBox.Show("Would you like to see the simple version?", 
    "MessageBox Example", MessageBoxButton.OKCancel);

if (result == MessageBoxResult.OK)
{
    MessageBox.Show("No caption, one button.");
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft