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


- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01