WinRT的C#MessageDialog.ShowAsync - 未经授权的访问异常 - [英] WinRT C# MessageDialog.ShowAsync - Unauthorized Access Exception -

查看:163
本文介绍了WinRT的C#MessageDialog.ShowAsync - 未经授权的访问异常 - 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不认为我需要粘贴代码。这是C#。



基本上,我创建了一个MessageDialog,表现出来,并UICommandInvokedHandler正在从一个按钮调用。



里面的处理程序,我这样做,可能会导致另一个MessageDialog.ShowAsync等物品被调用。然而,这第二个电话是给一个Unathorized访问异常。



我已经试过像引起事件试图迫使新MessageDialog要在UI线程创建的一些事情,但也做了同样的事情。



任何关于如何解决这个建议?粗略地说,我想给一个对话框,说:你确定吗?是/否如果是的话,它执行的胆量和可以弹出其他对话框,以提供随机错误的信息。



OK码:

 公共静态异步无效WriteMessageDialog(字符串消息,串buttonText1,UICommandInvokedHandler handler1,串buttonText2 ,UICommandInvokedHandler handler2)
{
MessageDialog msgDlg =新MessageDialog(消息);
msgDlg.Commands.Add(新UICommand(buttonText1,handler1));
msgDlg.Commands.Add(新UICommand(buttonText2,handler2));

//设置默认按钮启用和默认的Escape键按下
msgDlg.DefaultCommandIndex = 0;
msgDlg.CancelCommandIndex = 0;

//显示窗口
等待msgDlg.ShowAsync();
}



后来.....

  //他们原来的消息对话框
RTUtilities.WriteMessageDialog(
_resourceLoader.GetString(DetelePersonConfirm),
_resourceLoader.GetString(删除),
新UICommandInvokedHandler(this.CommandDeletePersonH​​andler),_resourceLoader.GetString(取消),
新UICommandInvokedHandler(this.CommandCancelHandler));



调用这个......

 专用异步无效CommandDeletePersonH​​andler(IUICommand命令)
{
MessageDialog msgDlg =新MessageDialog(_resourceLoader.GetString(DeleteIndividualError));
等待msgDlg.ShowAsync();
}


解决方案

那么,核心问题是,你试图打开一个MessageDialog而一个仍然在发挥作用。



有可能会更优雅的办法,但你可以使用的 ShowAsync 来确定所选择的命令然后显式调用它的处理程序,这种方式出现的第二个之前,首先弹出被驳回。就这样结束了一个快速测试表明是可行的。


I don't think I need to paste code. This is C#.

Basically, I have a MessageDialog Created, Show it, and have UICommandInvokedHandler being called from a button.

Inside that Handler, I do other items that could cause another MessageDialog.ShowAsync to be called. However, this second call is giving an Unathorized Access Exception.

I've tried some things like causing an event trying to force the new MessageDialog to be created on the UI THread, but that did the same thing.

Any suggestions on how to get around this? Roughly, I am trying to give a Dialog to say "Are you sure? Yes/No" If yes, it does the guts of execution and can pop up other Dialogs to give random error information.

Ok Code:

    public static async void WriteMessageDialog(string message, string buttonText1, UICommandInvokedHandler handler1, string buttonText2, UICommandInvokedHandler handler2)
    {
        MessageDialog msgDlg = new MessageDialog(message);
        msgDlg.Commands.Add(new UICommand(buttonText1, handler1));
        msgDlg.Commands.Add(new UICommand(buttonText2, handler2));

        // Set the default button to be enabled and default on escape key pressed
        msgDlg.DefaultCommandIndex = 0;
        msgDlg.CancelCommandIndex = 0;

        // Show the window
        await msgDlg.ShowAsync();
    }

Later.....

// THey original Message Dialog
RTUtilities.WriteMessageDialog(
       _resourceLoader.GetString("DetelePersonConfirm"),         
       _resourceLoader.GetString("Delete"), 
       new UICommandInvokedHandler(this.CommandDeletePersonHandler), _resourceLoader.GetString("Cancel"), 
       new UICommandInvokedHandler(this.CommandCancelHandler));

Calls this.....

    private async void CommandDeletePersonHandler(IUICommand command)
    {
        MessageDialog msgDlg = new MessageDialog(_resourceLoader.GetString("DeleteIndividualError"));
        await msgDlg.ShowAsync();
    }

解决方案

Well, the core of the problem is you're trying to bring up a MessageDialog while one is still in play.

There may be more elegant approaches, but you could use the return of ShowAsync to identify the selected command then explicitly call its handler, that way the first popup is dismissed before the second appears. A quick test on this end indicates that would work.

这篇关于WinRT的C#MessageDialog.ShowAsync - 未经授权的访问异常 - 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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