简体   繁体   English

Windows Phone 8.1 RT-保存和加载页面状态

[英]Windows Phone 8.1 RT - Saving and loading page state

I have 3 pages: first - MainPage, second - PivotPage, and third - SimplePage. 我有3页:第一页-MainPage,第二页-PivotPage,第三页-SimplePage。 I want to save the PivotPage state when I'm navigate to SimplePage and load it when go back. 我想在导航到SimplePage时保存PivotPage状态,并在返回时加载它。 I tried to use NavigationHelper class but it also saves and load PivotPage state when I back from PivotPage to MainPage and then navigate to PivotPage again, which is not desirable. 我尝试使用NavigationHelper类,但是当我从PivotPage返回MainPage然后再次导航到PivotPage时,它也保存并加载PivotPage状态,这是不希望的。 Does anyone can help me handle this? 有人可以帮我解决这个问题吗?

EDIT: 编辑:

I have 4 cases: 我有4种情况:

  1. page with hub 带枢纽的页面
  2. page with pivot 带枢轴的页面
  3. page with pivot with lists 页面与列表的页面
  4. page with list 列表页面

How to save and load position of selected item there? 如何在其中保存和加载所选项目的位置?

Maybe this is what you need 也许这就是你所需要的

add this to your constructor 将此添加到您的构造函数

    this.NavigationCacheMode = NavigationCacheMode.Required;

There are probably many ways to do what you want, but maybe simple flag would be sufficient (hence loading the state is fired in OnNavigatedTo ): 可能有很多方法可以做您想要的事情,但是简单的标志也许就足够了(因此在OnNavigatedTo触发了加载状态):

// provide a flag 
private bool ifLoadData = false;

// set the flag before state is loaded
protected override void OnNavigatedTo(NavigationEventArgs e)
{
    ifLoadData = e.NavigationMode == NavigationMode.Back;
    // rest of the code

// then in LoadState just check if you want your data to be loaded
private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
    if (ifLoadData)
    {
       // load data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM