MessageDialog.CancelCommandIndex Property

Gets or sets the index of the command you want to use as the cancel command. This is the command that fires when users press the ESC key.

Syntax

public:
property uint32 CancelCommandIndex {
         uint32 get ();
         void set (uint32 value);
}  

Property value

Type: uint32 

  The index of the cancel command.

Remarks

Use message dialogs to send critical or blocking messages and questions from the app.

Value When to use
≥0 The dialog offers a safe default choice that is the equivalent of cancellation, like “Cancel” or “Close.” Set CancelCommandIndex to the index of the command handler for that cancel/close command, so that when the user dismisses the dialog through a noncommital action, like pressing ESC, the API returns the command handler you want.
Note Generally, you should avoid creating dialogs that can be dismissed this way and that re-launch asking the same question or sending the same message again and again. They make the app noisy and tend to annoy users.
-1 The user is required to make an explicit decision like tapping a specific button on the dialog. This ensures that the user can’t dismiss the dialog through a noncommital action like pressing ESC.
-2 Not recommended.The dialog is not dismissed when the user presses ESC or during an incoming contract activation; however, if the app re-uses the main app window when responding to incoming activations, the dialog’s command handlers will no longer be valid. Because the API doesn’t handle this behavior, we recommend not using this value.

Error handling on dismissal by a contract activation

If the app receives an incoming contract activation (like from Search, Share, Settings, Devices or the File Picker contracts) while the dialog is showing, the dialog is programmatically dismissed, regardless of the property value that has been set for the CancelCommandIndex.

To help you handle this case, the API returns a dummy command handler. You, then, can decide how to handle and react to the error.

Requirements

Namespace: Windows.UI.Popups

Metadata: windows.winmd

See also

Reference

MessageDialog Class

MessageDialog Members

Windows.UI.Popups Namespace