简体   繁体   English

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

[英]Close App on back button when on certain page

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. 我已经阅读了一些文章,发现只能通过抛出未处理的异常来关闭Windows Phone应用程序,该异常将关闭该应用程序。

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. 因此,后退按钮将正常工作,但是当它最终落在名为“ noBack.xaml”的页面上时,后退按钮应关闭该应用程序。

EDIT 编辑

Actually on second thought, even just disabling the back button on that page would be awesome... 实际上,经过深思熟虑,即使只是禁用该页面上的“后退”按钮也很棒……

thanks! 谢谢! :) :)

Just clear the backstack when you're on NoBack.xaml : 在使用NoBack.xaml时,只需清除后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. 这样,下次用户按下返回按钮时,它将退出应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM