我正在尝试使用 3 个命令将 MessageDialog 添加到 Windows Phone 8.1 应用程序(WinRT)。查看 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 Phone 应用程序时,添加第三个命令没有问题,但是当它到达 await messageDialog.ShowAsync() 行时,它会因未处理的异常而崩溃。有趣的是,当您添加 4 个命令时,它不会像桌面应用程序那样崩溃。为此,当您尝试添加第 4 个命令时,它将引发异常。在电话上,它不会有问题,但是当它尝试显示 messageDialog 时它将无法工作。
我是否遗漏了什么,或者当您在打电话时,MessageDialog 上的最大命令数是否悄悄地从 3 降低到 2?