2016-03-08 69 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

更新與源代碼 –

相關問題