C# MessageDialog在Windows Phone 8.1上使用3个命令中断
我正在尝试使用3个命令向windows phone 8.1应用程序(WinRT)添加MessageDialog。查看MessageDialog的文档: 它说“对话框有一个命令栏,最多可以支持三个命令”,所以我认为这不会是一个问题。我以他们的例子(可以在文档中找到)做了一个简单的测试应用,它在桌面和windows phone上都运行得非常好。然后,我采用了相同的示例,并向其中添加了一个命令:C# MessageDialog在Windows Phone 8.1上使用3个命令中断,c#,windows-runtime,windows-phone-8.1,messagedialog,C#,Windows Runtime,Windows Phone 8.1,Messagedialog,我正在尝试使用3个命令向windows phone 8.1应用程序(WinRT)添加MessageDialog。查看MessageDialog的文档: 它说“对话框有一个命令栏,最多可以支持三个命令”,所以我认为这不会是一个问题。我以他们的例子(可以在文档中找到)做了一个简单的测试应用,它在桌面和windows phone上都运行得非常好。然后,我采用了相同的示例,并向其中添加了一个命令: var messageDialog = new MessageDialog("No internet c
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应用程序时,添加第3个命令没有问题,但当它到达wait messageDialog.ShowAsync()行时,它将崩溃,并出现未经处理的异常。有趣的是,当您添加4个命令时,它不会以与桌面应用程序相同的方式崩溃。因此,当您尝试添加第4个命令时,它将抛出异常。在手机上,它不会有问题,但当它试图显示messageDialog时,它将无法工作
我是否遗漏了什么,或者当你在打电话时,MessageDialog上的最大命令数是否会悄悄地从3个减少到2个 以下事件只能使用两个命令
Windows.UI.Popups.MessageDialog
这里有一个例子
private async void Button_Click(object sender, RoutedEventArgs e)
{
//Message Box.
MessageDialog msg = new MessageDialog("Here's the content/string.", "Hello!");
//Commands
msg.Commands.Add(new UICommand("Ok", new UICommandInvokedHandler(CommandHandlers)));
msg.Commands.Add(new UICommand("Quit", new UICommandInvokedHandler(CommandHandlers)));
await msg.ShowAsync();
//end.
}
public void CommandHandlers(IUICommand commandLabel)
{
var Actions = commandLabel.Label;
switch (Actions)
{
//Okay Button.
case "Ok" :
MainpageName.Focus(Windows.UI.Xaml.FocusState.Pointer);
break;
//Quit Button.
case "Quit" :
Application.Current.Exit();
break;
//end.
}
}
我想我们在WinRT for Phone的默认MessageDialog中最多只能使用2个命令。好的,谢谢你的回复。我可以想出一个方法来解决这个问题,如果文档中包含了它就好了,不过。。。