7
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 
4

1 回答 1

11

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

初始化对话框时:

myContentDialog.Closing += ContentDialog_Closing; 

事件处理程序:

void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
{
    if (doNotClose)
    {
        args.Cancel = true;
    }
}
于 2015-03-02T16:50:47.753 回答