我正在尝试使用3个命令将MessageDialog添加到Windows Phone 8.1应用程序(WinRT).查看MessageDialog的文档:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.popups.messagedialog.aspx
它说"对话框有一个命令栏,可以支持最多三个命令",所以我认为这不会是一个问题.我拿了他们的例子(在文档中找到)并制作了一个简单的测试应用程序,它在桌面和Windows手机上都运行得很好.然后,我采用相同的示例并向其添加了一个命令:
var messageDialog = new MessageDialog("No internet connection has been found.");
// Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers
messageDialog.Commands.Add(new UICommand(
"Try again",
new UICommandInvokedHandler(this.CommandInvokedHandler)));
messageDialog.Commands.Add(new UICommand(
"Something else",
new UICommandInvokedHandler(this.CommandInvokedHandler)));
messageDialog.Commands.Add(new UICommand(
"Close",
new UICommandInvokedHandler(this.CommandInvokedHandler)));
// Set the command that will be invoked by default
messageDialog.DefaultCommandIndex = 0;
// Set the command to be invoked when escape is pressed
messageDialog.CancelCommandIndex = 1;
// Show …Run Code Online (Sandbox Code Playgroud)