如何防止在Windows Phone 8.1中按Home键时关闭ContentDialog?
问题描述:
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
答
为了防止关闭对话框处理其Closing事件,并在其ContentDialogClosingEventArgs参数设置Cancel为true。
当初始化对话框:
myContentDialog.Closing += ContentDialog_Closing;
事件处理程序:
void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
{
if (doNotClose)
{
args.Cancel = true;
}
}