2016-03-08 40 views
0

我有一个应用程序,它在Windows 10上按预期工作。但在Windows 10 Mobile上,当用户按下后退按钮时,应用程序关闭。在我回来的请求事件处理程序中,我甚至评论了GoBack()方法,但应用程序仍然关闭。后退按钮激动关闭我的应用程序在Windows 10移动

private void MobileNavigationService_BackRequested(object sender, BackRequestedEventArgs e) 
    { 
     e.Handled = true; 

     var navigationService = UnityConfiguration.Resolve<IMobileNavigationService>(); 

     if (navigationService.CanGoBack()) 
     { 
      //navigationService.GoBack(); 
     } 
    } 

我有一种感觉,即使我设置e.Handled = TRUE它忽略它,就像没有处理程序。

更新

作为附加信息

应用只有一个页面,壳牌。它有常见的东西,如菜单和标题栏。它也有框架。在框架中,我打开所有其他页面。因此,回顾一下,对于我的应用程序而言,意味着要回到那个框架,而不是整个应用程序。我想覆盖默认行为。

+0

这是默认的行为。你能指望什么? –

+0

是的,但当* e.Halded *设置为真时,必须覆盖默认行为。 [看到这里](https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.core.systemnavigationmanager.aspx) – TIKSN

+0

我相信应用程序并没有真正关闭 - 它只是切换到开始屏幕,但应用程序继续在后台。这是用户期望发生的事情。 –

回答

-1
  • 为BackRequested设置一个事件处理程序并导航回页面堆栈。
  • 根据应用程序的内部页面堆栈启用和禁用标题栏后退按钮。

你可以从微软这个DEMO在GitHub上

Back Button Sample

protected override void OnNavigatedTo(NavigationEventArgs e) 
    { 
     bool optedIn = false; 

     if ((bool)e.Parameter) 
     { 
      optedIn = true; 

     } 

     Frame rootFrame = Window.Current.Content as Frame; 

     if (rootFrame.CanGoBack && optedIn) 
     { 
      // If we have pages in our in-app backstack and have opted in to showing back, do so 
      SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; 
     } 
     else 
     { 
      // Remove the UI from the title bar if there are no pages in our in-app back stack 
      SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; 
     } 
    } 
+0

这是从链接复制粘贴... – Ian

+0

更新与源代码 –

相关问题