2

Say I have two pages, A and B.

The user can modify things on page A then navigate to page B. When he is on page B, he clicks the "Back" button to go to page A. Everything that has been done previously is lost.

There is a way to get the exact same state by using

this.NavigationCacheMode = 
        Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;

But is there a way to know whether the page is opened for the first time a by using the back button?

1 Answer 1

2

yes it is:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
  if (e.NavigationMode == NavigationMode.Back)
  {
    // LoadPreviousSate...
  }
}

You also should've a look at ApplicationExecutionState (in OnLaunched event in App.xaml). If you navigate to Page B, Apps suspends, App continues, user navigates to Page A the NavigationMode will be New!

2
  • Thanks. Is there a way to save things that I would like to reuse? (Some text that was not saved by the mechanism or something else) May 2, 2012 at 12:28
  • You have to handle this by your own. If there is some text in a TextBox you want to save (and which is not saved by caching), write it to isolated storage or appsettings. You can also try to set this.NavigationCacheMode = NavigationCacheMode.Required;
    – Jan K.
    May 2, 2012 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.