Getting Started with Windows 8 development (v) pop-up prompt box messagedialog with await, async keyword

Source: Internet
Author: User

In the previous Silverlight, WPF pop-up window prompts are displayed in the MessageBox class, now Windows 8 uses the Messagedialog class in the Windows.UI.Popups namespace instead of MessageBox.

The Messagedialog class has the following common methods and properties:

Showasync (): Asynchronous pop-up message box.

Commands: Add a command to synchronize the buttons on the pop-up screen.

Defaultcommandindex: Sets the index of the default button and presses the ENTER key to activate the command button for the index

Cancelcommandindex: Sets the index of the Cancel Exit button, and pressing ESC activates the corresponding command button for the index

Title: Caption of pop-up message box

Async: When used for method declarations, this keyword tells the compiler that there may be a await keyword in the method body.

Await: Analog synchronous wait for asynchronous operations, declaring asynchronous operations with this keyword waiting for the asynchronous operation to complete before continuing, but not blocking the UI thread.

Note: The method body using the AWAIT keyword must use the Async declaration method

Now we look at Messagedialog, async, await by an example:

<grid background= "{StaticResource Applicationpagebackgroundthemebrush}" > <button Content= " "Horizontalalignment=" left "margin=" 430,196,0,0 "verticalalignment=" "The Top" height= "Wuyi" Widt H= "114" click= "First_click"/> <button content= "secend Msg" horizontalalignment= "left" margin= "606,196,0,0" verticalalignment= "Top" height= "Wuyi" width= "114" click= "Secend_click"/> <button content= "Third Msg" horizontalalignment= "left" margin= "788,196,0,0" verticalalignment= "Top" Height
            = "Wuyi" width= "114" click= "Third_click"/> <button content= "Fourth MSG" horizontalalignment= "left" Margin= "975,196,0,0" verticalalignment= "Top" height= "WU" width= "114" click= "Fourth_click"/> & Lt
                   TextBlock horizontalalignment= "left" name= "Tbtext" margin= "573,160,0,0" textwrapping= "Wrap" Text= "TextbloCK "verticalalignment=" Top "height=" "width=" 565 "fontsize="/> </Grid> 

One: The simplest of messagedialog

Private async void First_click (Object 

sender, RoutedEventArgs e)   
{   
    messagedialog msg = new Messagedialog (" Hello world! This is the first hint. ");   
    Msg. Title = "Hint 1";   
    var msginfo = await Msg. Showasync ();   
}

Two: custom Command set message box

Private async void Secend_click (object sender, 

RoutedEventArgs e)   
        {   
            Messagedialog msg1 = new Messagedialog ("Hello world! This is the second hint.");   
            Msg1. Title = "Hint 2";   
            MSG1.COMMANDS.ADD ("OK", command =>   
            {   
                this.tbText.Text = "You clicked the OK button, the second set of prompts";   
            });   
            MSG1.COMMANDS.ADD (The New Uicommand ("Cancel", command =>   
            {   
                this.tbText.Text = "You clicked the Cancel button, the second set of prompts";   
            }));   
            var msg1info = await msg1. Showasync ();   
        }

Three: Using await analog synchronization to get the code snippet that is currently running the response using the command ID

Private 

async void Third_click (object sender, RoutedEventArgs e)   
        {   
            Messagedialog msg1 = new Messagedialog (" Hello world! This is the third hint. ");   
            Msg1. Title = "Hint 3";   
            MSG1.COMMANDS.ADD (New Uicommand ("OK", NULL, 0));   
            MSG1.COMMANDS.ADD (New Uicommand ("Cancel", NULL, 1));   
            Msg1. Defaultcommandindex = 0;   
            Msg1. Cancelcommandindex = 1;   
            var msg1info = await msg1. Showasync ();   
            Switch (Convert.ToInt32 (msg1info). Id)   
            {case    
                0:   
                     this.tbText.Text = "You clicked the OK button, the third set of prompts";   
                Case 1:   
                    this.tbText.Text = "You clicked the Cancel button, the third set of prompts";   
                Default: Break   
                    ;   
            }   
        }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.