2015-03-02 62 views
3
private IAsyncOperation<ContentDialogResult> _Task = null; 
private ContentDialog _message = null;    


     _message = new ContentDialog() 
     { 
      Content = "Hello", 
      PrimaryButtonText = "EXIT", 
      IsPrimaryButtonEnabled = true, 
     }; 

     _message.PrimaryButtonClick += message_PrimaryButtonClick; 
     _Task = _message.ShowAsync(); 

這裏我創建了一個用於內容對話框的任務,以便我可以從代碼明確地關閉ContenDialog。如何防止在Windows Phone 8.1中按Home鍵時關閉ContentDialog?

How can I prevent dialog from closing when Home key is pressed and relaunched 

回答

6

爲了防止關閉對話框處理其Closing事件,並在其ContentDialogClosingEventArgs參數設置Cancel爲true。

當初始化對話框:

myContentDialog.Closing += ContentDialog_Closing; 

事件處理程序:

void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args) 
{ 
    if (doNotClose) 
    { 
     args.Cancel = true; 
    } 
}