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
这篇关于如何以编程方式关闭消息对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何以编程方式关闭消息对话框


基础教程推荐
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01