Original: Quickly build Windows 8 style apps 22-messagedialog
This post mainly introduces Messagedialog overview, Messagedialog Common Properties and methods, how to build Messagedialog
Messagedialog Overview
Messagedialog refers to a dialog box.
The command bar of the dialog box contains a maximum of three commands. If we specify any command, a default command will be added to the dialog box to close the dialog box.
After the dialog pops up, all elements in the interface will be displayed below the dialog box, and any touch events will be blocked until the user responds to the dialog box.
In addition, the dialog should be used sparingly.
Note: The MessageBox object is canceled in the Windows 8 style app, instead of the Messagedialog object.
Messagedialog Common Properties and methods
The Messagedialog class contains two types of constructors:
1) messagedialog (String)
Public Messagedialog (string content);
The content parameter represents the information that is displayed to the user in the dialog box.
2) Messagedialog (string,string)
Public Messagedialog (stringstring title);
The content parameter represents the information displayed in the dialog box to the user, and the title parameter represents the caption information displayed in the dialog box.
Common methods of the Messagedialog class:
1) Showasync ()
Public Iasyncoperation<iuicommand> Showasync ();
Displays the dialog box asynchronously.
Common properties of the Messagedialog class:
1)Cancelcommandindex property: Gets or sets the index of the Cancel command, the user presses the ESC key and executes the cancel command;
2)Commands property: Gets the command displayed in the command bar of the dialog box;
3)content Properties: Gets or sets the main content displayed in the dialog box;
4)Defaultcommandindex property: Gets or sets the index of the default command, and the user presses the ENTER key to execute the default command;
5)Options properties: Gets or sets the options in the dialog box;
6)Title property: Gets or sets the title of the dialog box;
Note: The Messagedialog class is not very optimized and we need to consider its impact in the thread model. Also refer to multithreading in Windows 8 Store applications: Using Windows Runtime objects in a multithreaded environment.
How to build Messagedialog
The common Messagedialog object rendering has the following effects:
Effect 1: Default Shutdown command
No command to close the dialog box is set in C # code. If we do not set the Close command, the system adds a close command by default.
Private void Messagedialogshow ()
{
New Messagedialog ("Default shutdown command");
await Messagedialog.showasync ();
}
Effect 2: Adding custom commands
Add two commands to your C # code and specify what actions to perform when each command executes. Both the default command index and the Cancel command index are set.
Private void Messagedialogshow ()
{
New Messagedialog ("Invalid network connection");
MESSAGEDIALOG.COMMANDS.ADD (new Uicommand ("Retry"new Uicommandinvokedhandler (this . (Commandinvokedhandler)));
MESSAGEDIALOG.COMMANDS.ADD (new Uicommand ("Cancel"new Uicommandinvokedhandler ( this. (Commandinvokedhandler)));
Set the default command index
Messagedialog.defaultcommandindex = 0;
Set the Cancel command index
Messagedialog.cancelcommandindex = 1;
await Messagedialog.showasync ();
}
Private void Commandinvokedhandler (Iuicommand command)
{
Here you write the operation code executed by the command.
}
We can also use lambda expressions when adding commands.
MESSAGEDIALOG.COMMANDS.ADD (new Uicommand ("Retry", [command] = =
{
Perform actions
}));
MESSAGEDIALOG.COMMANDS.ADD (new Uicommand ("Cancel", [command] = =
Perform actions
}));
You can also specify the index of the custom command.
MESSAGEDIALOG.COMMANDS.ADD (new Uicommand ("Don ' t install"null, 0));
MESSAGEDIALOG.COMMANDS.ADD (new Uicommand ("Install updates"null, 1));
Example code for Messagedialog: Message dialog Sample.
Quickly build Windows 8 style apps 22-messagedialog