Windows Phone Back KeyPress + MessageBox 使应用程序在没有选择的情况下崩溃 [英] Windows Phone Back KeyPress + MessageBox crashes the app without Selection

查看:20
本文介绍了Windows Phone Back KeyPress + MessageBox 使应用程序在没有选择的情况下崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题在后面的代码中覆盖 BackkeyPress 函数,在函数内部我有一个简单的消息框可以返回或取消导航(留在当前页面),当没有选择(确定或取消)并且 Messagebox 是打开很长时间,应用程序崩溃,当我尝试调试时,不会抛出任何异常并且应用程序保持状态,除非按下确定或取消,但在正常运行(没有调试器)时,崩溃很明显.

I have a strange issue overriding BackkeyPress Function in code behind, inside the function i have a simple message box to Go back or cancel navigation ( stay in current page ), when no choice is made (ok or cancel ) and Messagebox is open for long time, Application crashes, when i try to debug, no exception is thrown and App remains in the state unless OK or cancel is pressed , but on Normal run ( without debugger ) the crash is apparent.

    protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
    {

        string caption = "exit?";
        string message = "Do you still want to exit?";
        e.Cancel = MessageBoxResult.Cancel == MessageBox.Show(message, caption,           
        MessageBoxButton.OKCancel);

        base.OnBackKeyPress(e);

    }

推荐答案

http://msdn.microsoft.com/en-US/library/windowsphone/develop/jj206947(v=vs.105).aspx

在 Windows Phone 8 中,如果您调用 Show inOnBackKeyPress(CancelEventArgs) 或 BackKeyPress 的处理程序事件,应用程序将退出.

In Windows Phone 8, if you call Show in OnBackKeyPress(CancelEventArgs) or a handler for the BackKeyPress event, the app will exit.

您可以通过在不同线程上调用 Show 来解决此问题,如在以下步骤中描述.覆盖 BackKeyPress 或创建一个BackKeyPress 事件的处理程序.将 Cancel 设置为 true 以取消后退键按下动作.调度一个方法,显示消息框.如果用户选择离开应用程序,调用 Terminate(),否则,什么都不做.

You can work around this by calling Show on a different thread, as described in the following steps. Override BackKeyPress or create a handler for the BackKeyPress event. Set the Cancel to true to cancel the back key press action. Dispatch a method that shows the MessageBox. If the user chooses to leave the app, call Terminate(), otherwise, do nothing.

这篇关于Windows Phone Back KeyPress + MessageBox 使应用程序在没有选择的情况下崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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