如何在UWP中弹出消息?

Bor*_*vee 1 popup uwp

在我的Windows 8.1应用程序中,我使用MessageBox.Show()来弹出消息.这在UWP中已经消失了.我该如何显示信息?

小智 8

是的,确实是这样的,新方法是使用MessageDialog类.您必须创建该类型的对象.您还可以添加按钮.我认为这有点复杂.但你也可以在这里使用一些快捷方式.要显示消息,请使用以下命令:

await new MessageDialog("Your message here", "Title of the message dialog").ShowAsync();
To show an simple Yes/No message, you can do it like this:

MessageDialog dialog = new MessageDialog("Yes or no?");
dialog.Commands.Add(new UICommand("Yes", null));
dialog.Commands.Add(new UICommand("No", null));
dialog.DefaultCommandIndex = 0;
dialog.CancelCommandIndex = 1;
var cmd = await dialog.ShowAsync();

if (cmd.Label == "Yes")
{
    // do something
}
Run Code Online (Sandbox Code Playgroud)

  • 这不正是我昨天回答的吗? (2认同)

Rob*_*iel 5

看一看该Windows.UI.Popups.MessageDialog课程,然后尝试以下方法:

// 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();
Run Code Online (Sandbox Code Playgroud)