Save the page state when navigating out

2019-07-20 15:06发布

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条回答
我命由我不由天
2楼-- · 2019-07-20 15:48

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!

查看更多
登录 后发表回答