0

我正在构建的本质上是一个带有文本字段和结果列表的单页搜索应用程序。由于此应用程序仅包含一页,因此点击手机上的硬件后退按钮将杀死我的应用程序并将用户带到开始应用程序。

我认为,如果我能以某种方式覆盖此标准行为,即按返回会将用户带到同一页面上先前成功的搜索结果(如果有的话,则退出应用程序),我认为它将为用户提供更好的体验正常的背部会做)。

问题是是否可以以这种方式覆盖后退导航,如果可以,那么如何?

4

3 回答 3

1

You can catch the hardware back key press by overriding the OnBackKeyPress method in your page. You can detect cases where you want to perform an internal action rather than exit a page.

This is documented on MSDN here.

    protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
    {
        if (...)
        {
            // don't want to exit the app in this case
            e.Cancel;
        }

        base.OnBackKeyPress(e);
    }

Be careful to make sure you don't break exiting the application with the back key however, or else your application could fail Marketplace certification.

于 2012-12-04T12:47:47.620 回答
0
protected virtual void OnNavigatingFrom(
    NavigatingCancelEventArgs e
)

在您的页面中覆盖 OnNavigatingFrom 并执行 e.Cancel = true

protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
e.Cancel = true;
//Other code

}

http://msdn.microsoft.com/en-us/library/ms607458(vs.95 )

于 2012-12-04T11:11:11.067 回答
0

你应该做这个:

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
 e.Cancel = MessageBox.Show("Exit?", "Page", MessageBoxButton.OKCancel) != 
 MessageBoxResult.OK;
 base.OnBackKeyPress(e);
}
于 2014-03-31T11:29:27.733 回答