在特定页面上关闭后退按钮上的应用程序

在特定页面上关闭后退按钮上的应用程序

本文介绍了在特定页面上关闭后退按钮上的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了一些书,发现只能通过抛出将关闭应用程序的未处理异常来关闭 Windows Phone 应用程序.

I've done some reading and found that one can only close a windows phone app by throwing an un-handled exception that will close the app.

所以我的问题是,如何为手机上的物理后退按钮做到这一点?

So my question is, how does one do that for the physical back button on the phone?

如何让后退按钮关闭应用仅当它在某个页面上时?

And how does one have the back button close the app only if it's on a certain page ?

所以后退按钮会正常工作,但是当它最终落在一个名为noBack.xaml"的页面上时,后退按钮应该关闭应用程序.

So the back button would work as normal, but when it eventually falls on a page called 'noBack.xaml' the back button should close the app.

编辑

实际上仔细想想,即使只是禁用该页面上的后退按钮也很棒...

Actually on second thought, even just disabling the back button on that page would be awesome...

谢谢!:)

推荐答案

只需在 NoBack.xaml 上清除 backstack:

Just clear the backstack when you're on NoBack.xaml:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);

    while (this.NavigationService.BackStack.Any())
    {
       this.NavigationService.RemoveBackEntry();
    }
}

这样,下次用户按下后退按钮时,就会退出应用程序.

This way, the next time the user press the back button, it will exit the application.

这篇关于在特定页面上关闭后退按钮上的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 07:20