Close App on back button when on certain page

China☆狼群 提交于 2020-01-06 19:45:12

问题


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 ?

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.

EDIT

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

thanks! :)


回答1:


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.



来源:https://stackoverflow.com/questions/13417380/close-app-on-back-button-when-on-certain-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!