C # UWP Windows 10

Actually a subject: In Windows Phone 8 applications it was possible to use NavigationManager . How to programmatically call GoBack() in Windows 10 applications?

    1 answer 1

    Moving to another page is done in much the same way as in WP8:

     this.Frame.Navigate(typeof(SettingsPage)); 

    In order to go back you can do this:

     Frame rootFrame = Window.Current.Content as Frame; if (rootFrame.CanGoBack) { rootFrame.GoBack(); } 

    Please note that the "Back" button of the window can be displayed or hidden like this:

     SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = ((Frame)sender).CanGoBack ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed; 

    Well, you can add handling of the event of clicking on this button:

     SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested; 
    • This I know and use. And what if there is no access to rootFrame and you need to imitate pressing the back button - SYL
    • How so there is no access to rootFrame? Look at the code: Frame rootFrame = Window.Current.Content as Frame; The current window content is rootFrame - Alexej Sommer
    • And if there was another Content . The back button calls OnBackRequested in App.cs. There may be its own processing that will replace the windows (for example, the PIN input window on SplitView) So the current window has rootFrame.CanGoBack = false - always - SYL
    • I wrote how to programmatically implement GoBack (), but I don’t quite understand you about window replacement. - Alexej Sommer
    • Object reference not set. - SYL