[英]UWP Message Popup
在UWP應用中,當我在按鈕單擊事件中使用時,如以下代碼所示,可以打開MessageDialog:
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();
}
但是,當我嘗試在for循環中調用同一事件處理程序時,我的應用程序看不到任何內容。
for (int i = 0; i < 10; i++)
{
TestBtn_Click(null, null);
}
我希望應用程序暫停,並像Console.ReadLine()一樣顯示一些數據。
將返回類型從void更改為Task ,這將使消息對話框等待。
// 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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.