Save the page state when navigating out

北城以北 提交于 2019-12-11 03:37:40

问题


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:


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!



来源:https://stackoverflow.com/questions/10413387/save-the-page-state-when-navigating-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!