如何防止在Windows Phone 8.1中按下主页键时关闭ContentDialog ..?

Jos*_*gal 3 messagedialog windows-phone-8.1

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();
Run Code Online (Sandbox Code Playgroud)

在这里,我创建了一个内容对话框的任务,以便我可以从代码中显式关闭ContenDialog.

 How can I prevent dialog from closing when Home key is pressed and relaunched 
Run Code Online (Sandbox Code Playgroud)

Rob*_*SFT 6

要阻止对话框关闭,请处理其Closing事件,并在其ContentDialogClosingEventArgs参数中将Cancel设置为true .

初始化对话框时:

myContentDialog.Closing += ContentDialog_Closing; 
Run Code Online (Sandbox Code Playgroud)

事件处理程序

void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
{
    if (doNotClose)
    {
        args.Cancel = true;
    }
}
Run Code Online (Sandbox Code Playgroud)