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

时间:2015-03-02 10:14:10

标签: windows-phone-8.1 messagedialog

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。

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

1 个答案:

答案 0 :(得分:6)

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

初始化对话框时:

myContentDialog.Closing += ContentDialog_Closing; 

事件处理程序:

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