如何以编程方式关闭消息对话框对话框、消息、方式

由网友(家住魔仙堡)分享简介:我正在尝试关闭我的 WinRT 应用程序中的 MessageDialog.我注意到如果我尝试一次显示两个消息对话框,我会得到一个 UnauthorizedAccessException.为避免这种情况,我想关闭现有的消息对话框(如果它已打开).我用它来显示对话框:I am trying to close a Mess...

我正在尝试关闭我的 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

阅读全文

相关推荐

最新文章