导航出时保存页面状态 [英] Save the page state when navigating out
问题描述
假设我有两页,A 和 B.
Say I have two pages, A and B.
用户可以修改页面 A 上的内容,然后导航到页面 B.当他在页面 B 上时,他单击返回"按钮转到页面 A.之前所做的一切都将丢失.
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?
推荐答案
是的:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.NavigationMode == NavigationMode.Back)
{
// LoadPreviousSate...
}
}
您还应该查看 ApplicationExecutionState
(在 App.xaml 的 OnLaunched
事件中).如果您导航到页面 B,应用程序暂停,应用程序继续,用户导航到页面 A,NavigationMode
将是 New
!
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
!
这篇关于导航出时保存页面状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!