简体   繁体   中英

UWP Message Popup

In an UWP app, I can get the MessageDialog to open when I use in a button click event like the code below:

 private async void TestBtn_Click(object sender, RoutedEventArgs e)
    {
        // Create a MessageDialog
        var dialog = new MessageDialog("This is my content", "Title");
        // If you want to add custom buttons
        dialog.Commands.Add(new UICommand("Click me!", delegate (IUICommand command)
        {
            // Your command action here
        }));
        // Show dialog and save result
        var result = await dialog.ShowAsync();
    }

But when I try to call the same event handler in a for loop, I see nothing in my app.

        for (int i = 0; i < 10; i++)
        {
            TestBtn_Click(null, null);
        }

I want the app to pause, and display some data like the Console.ReadLine() does.

Change your return type from void to Task which will make the message dialog to await.

// your function
private async Task TestBtn_Click(object sender, RoutedEventArgs e)

// where you call
for (int i = 0; i < 10; i++)
 {
  await TestBtn_Click(null, null);
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM