如何关闭消息对话框编程 [英] How to close Message Dialog programmatically

查看:175
本文介绍了如何关闭消息对话框编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的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();
        }
        );
    }



我怎么关闭它?

How do I close it?

推荐答案

而不是试图找到一种方法来关闭它,试试这个
声明一个实例变量AsyncCommand;

instead of trying to find a way to close it, try this declare a instance variable for AsyncCommand;

AsyncCommand command;

command = md.ShowAsync();



然后在您的commandhandler,运行你的方法检查,如果命令为null

then in your commandhandler, before running your method check if command is null

if(command!=null)
{
command.Cancel();
}



//
做的东西/ TRYAGAIN块

// do stuff/ tryagain block

这篇关于如何关闭消息对话框编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆