How to close Message Dialog programmatically(如何以编程方式关闭消息对话框)
问题描述
我正在尝试关闭我的 WinRT 应用程序中的 MessageDialog.我注意到如果我尝试一次显示两个消息对话框,我会得到一个 UnauthorizedAccessException.为避免这种情况,我想关闭现有的消息对话框(如果它已打开).我用它来显示对话框:
I am trying to close a MessageDialog in my WinRT App. I have noticed if I attempt to show two message dialogs at once, I get an UnauthorizedAccessException. To avoid this, I want to close the existing message dialog if it is open. I use this to show the dialog:
MessageDialog md = new MessageDialog(" ");
private void MessageBox(string s)
{
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
md.Content = s;
//CLOSE HERE
md.ShowAsync();
}
);
}
如何关闭它?
推荐答案
与其想办法关闭它,不如试试这个为 AsyncCommand 声明一个实例变量;
instead of trying to find a way to close it, try this declare a instance variable for AsyncCommand;
AsyncCommand command;
command = md.ShowAsync();
然后在你的命令处理程序中,在运行你的方法之前检查命令是否为空
then in your commandhandler, before running your method check if command is null
if(command!=null)
{
command.Cancel();
}
//做事/再次尝试阻止
// do stuff/ tryagain block
这篇关于如何以编程方式关闭消息对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何以编程方式关闭消息对话框
基础教程推荐
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
