The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
[UWP] Why rootFrame.CanGoBack is always false RRS feed

  • Question

  • 1. Why rootFrame.CanGoBack is always false ?

    private void OnBackRequested(object sender, BackRequestedEventArgs e)
            {
                Frame rootFrame = Window.Current.Content as Frame;

                if (rootFrame.CanGoBack)
                {
                    e.Handled = true;
                    rootFrame.GoBack();
                }
            }

    2. Can you provide link - how to realize back logic for my application.

    Do I need to write history manaully.

    If it saved automatically - what history is saved ?


    • Edited by SmartWhy Friday, November 18, 2016 1:54 PM
    Thursday, November 17, 2016 3:29 PM

Answers

  • Please refer to the following page on MSDN.

    Back button navigation: https://msdn.microsoft.com/en-us/library/windows/apps/mt465734.aspx

    If you create a new page called "BlankPage1.xaml" and navigate to it from your MainPage like this:

    private void Button_Click(object sender, RoutedEventArgs e)
            {
                Frame.Navigate(typeof(BlankPage1));
            }

    ...you should be able to go back to the main page from a custom event handler in BlankPage1.xaml.cs like this:

    private void Button_Click(object sender, RoutedEventArgs e)
            {
                Frame rootFrame = Window.Current.Content as Frame;
                if (rootFrame == null)
                    return;
    
                if (rootFrame.CanGoBack)
                {
                    rootFrame.GoBack();
                }
            }
    

    Please refer to the following thread for more information and suggestions: http://stackoverflow.com/questions/31832309/handling-back-navigation-windows-10-uwp


    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread

    • Marked as answer by SmartWhy Friday, November 18, 2016 1:55 PM
    Thursday, November 17, 2016 8:02 PM

All replies

  • Hello SmartWhy,

    Welcome to the Developing Universal Windows apps forum!

    Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools , and don't forget add tag to your question.

    Can you provide more code , and how you navigate to the other page?


    Make the community better together

    Thursday, November 17, 2016 5:17 PM
  • Please refer to the following page on MSDN.

    Back button navigation: https://msdn.microsoft.com/en-us/library/windows/apps/mt465734.aspx

    If you create a new page called "BlankPage1.xaml" and navigate to it from your MainPage like this:

    private void Button_Click(object sender, RoutedEventArgs e)
            {
                Frame.Navigate(typeof(BlankPage1));
            }

    ...you should be able to go back to the main page from a custom event handler in BlankPage1.xaml.cs like this:

    private void Button_Click(object sender, RoutedEventArgs e)
            {
                Frame rootFrame = Window.Current.Content as Frame;
                if (rootFrame == null)
                    return;
    
                if (rootFrame.CanGoBack)
                {
                    rootFrame.GoBack();
                }
            }
    

    Please refer to the following thread for more information and suggestions: http://stackoverflow.com/questions/31832309/handling-back-navigation-windows-10-uwp


    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread

    • Marked as answer by SmartWhy Friday, November 18, 2016 1:55 PM
    Thursday, November 17, 2016 8:02 PM
  • thank you. I found the source of the problem. I had three handlers. one in app.xaml and one in each for,. All checked for cangoback but one the firstone has handeld the go back, the others are going to return false on cangoback becasue the app has already gone back. Silly me. 

    Thanks fr your help.

    Tuesday, April 17, 2018 7:10 PM