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
答案 0 :(得分:6)
要阻止对话框关闭处理其Closing事件,并在其Cancel参数中将ContentDialogClosingEventArgs设置为true。
初始化对话框时:
myContentDialog.Closing += ContentDialog_Closing;
事件处理程序:
void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
{
if (doNotClose)
{
args.Cancel = true;
}
}