我正在尝试向Windows Phone 8.1应用程序(WinRT)添加一个带有3个命令的MessageDialog。查看MessageDialog的文档:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.popups.messagedialog.aspx
文档中说:“对话框具有命令栏,最多可以支持三个命令”,所以我认为这不应该是个问题。我使用了他们在文档中提供的示例,并将其制作成了一个简单的测试应用程序,在桌面和Windows Phone上都完美地运行。然后,我将相同的示例添加了一个单独的命令:
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 the message dialog
await messageDialog.ShowAsync();
这段代码在Windows桌面应用程序上运行良好,但是当我使用完全相同的代码尝试在Windows手机应用程序上运行时,它在添加第三个命令时没有问题,但当它到达 "await messageDialog.ShowAsync() "这一行时,就会崩溃并抛出一个未处理的异常。有趣的是,当您在桌面应用程序中添加第四个命令时,它不会像手机应用程序那样以相同的方式崩溃。对于桌面应用程序,它会在尝试添加第四个命令时抛出异常。但是在手机上,它不会有这个问题,但当它尝试显示messageDialog时,它无法正常工作。
我是否遗漏了什么,或者当您在手机上时,MessageDialog上的最大命令数会从3个悄然降至2个?