【发布时间】:2016-09-21 09:04:56
【问题描述】:
简而言之,我只想在某些页面上处理后退按钮以返回上一页,而在其余页面上忽略(让默认操作/关闭应用程序)。
因此,对于我的示例,我只想为 CurrentPage 处理后退按钮。所以,我把这段代码放在了我的 CurrentPage.xaml.cs
public CurrentPage()
{
this.InitializeComponent();
SystemNavigationManager.GetForCurrentView().BackRequested += App_BackRequested;
}
private void App_BackRequested(object sender, BackRequestedEventArgs e)
{
this.Frame.Navigate(typeof(PreviousPage), e);
e.Handled = true;
}
但是,当我进入上一页时,按后退按钮将再次转到上一页。我无法退出应用程序。
如果我在 PreviousPage.xaml.cs 上添加它,那么从 CurrentPage 按下 BackButton 将导致返回到 PreviousPage 并自动关闭应用程序。
public PreviousPage()
{
this.InitializeComponent();
SystemNavigationManager.GetForCurrentView().BackRequested += App_BackRequested;
}
private void App_BackRequested(object sender, BackRequestedEventArgs e)
{
Application.Current.Exit();
e.Handled = true;
}
你知道如何处理单页上的后退按钮吗?
【问题讨论】: