簡體   English   中英

MessageDialog在具有3個命令的Windows Phone 8.1上中斷

[英]MessageDialog breaks on Windows Phone 8.1 with 3 commands

我正在嘗試使用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 the message dialog
await messageDialog.ShowAsync();

這在Windows桌面應用程序上工作正常,但是當我使用完全相同的代碼並嘗試將其用於Windows手機應用程序時,添加第3個命令沒有問題但是當它到達等待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.
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM