【问题标题】:How to prevent going back after the user pressed the GoBack hardware button?用户按下GoBack硬件按钮后如何防止返回?
【发布时间】:2014-10-11 22:07:02
【问题描述】:

我有一个运行异步操作的页面。

当用户按下手机上的 H/W 后退按钮时,我希望应用程序被询问用户他是否“真的”想要退出该页面?如果答案是肯定的,则返回 GoBack,但如果答案是否定的,则留在同一页面上。

我该怎么做?

MessageBoxResult result = MessageBox.Show("Do you really want to leave this page?", "", MessageBoxButton.OKCancel);

    if ( result == MessageBoxResult.OK )
        {
        // .... Go Back
        }
    else
        {
        // .... Stay on the same page
        }

谢谢!

【问题讨论】:

    标签: c# windows-phone-8 navigation windows-phone-7.1 windows-phone-8.1


    【解决方案1】:

    覆盖 backkeypress 事件

    protected override void OnBackKeyPress(CancelEventArgs e)
    {
        if(MessageBox.Show("Are you sure you want to exit?","Exit?", 
                                MessageBoxButton.OKCancel) != MessageBoxResult.OK)
        {
            e.Cancel = true; 
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-19
      • 1970-01-01
      • 2012-05-17
      • 2023-04-02
      • 2018-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多