2010-11-19 53 views
1

在windows phone 7枢纽控制模板项目中,如果您从特定数据透视项目转到搜索页面并在手机上选择返回,则透视控制页面不会记住所选项目。它总是回到枢轴控制的第一项。WP7 pivotcontrol记住所选项目

你如何改变这种行为,所以如果你在第三个枢轴项目,你去搜索和回击,你回到第三个枢轴项目。

PRATIK

回答

3

当你按下搜索按钮,您的应用程序逻辑删除(换句话说,应用程序停止并保存在内存中,只要有可能)。它是完全由你(开发商)将如何处理它。该系统本身只做了几件事情来获得最后一次返回状态 - 就像导航到最后一页。 你可以在浏览器中将它想像成cookies。如果您按下后退按钮,浏览器将检查cookie是否存在,并使用cookie中的信息加载内容。

有几种方法可以处理它并为用户提供最好的用户体验。您可以将状态保存到State集合或直接保存到IsolatedStorage。在App.xaml.cs

使用事件
// Code to execute when the application is launching (eg, from Start) 
    // This code will not execute when the application is reactivated 
    private void Application_Launching(object sender, LaunchingEventArgs e) 
    { 
    } 

    // Code to execute when the application is activated (brought to foreground) 
    // This code will not execute when the application is first launched 
    private void Application_Activated(object sender, ActivatedEventArgs e) 
    { 

    } 

    // Code to execute when the application is deactivated (sent to background) 
    // This code will not execute when the application is closing 
    private void Application_Deactivated(object sender, DeactivatedEventArgs e) 
    { 
    } 

    // Code to execute when the application is closing (eg, user hit Back) 
    // This code will not execute when the application is deactivated 
    private void Application_Closing(object sender, ClosingEventArgs e) 
    { 
    } 

或事件为您的网页与枢轴

// set state 
    protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e) 
    { 
#if DEBUG 
     Debug.WriteLine("TOMBSTONING EVENT: OnNavigatedFrom at {0}", DateTime.Now.ToLongTimeString()); 
#endif 
     //try to locate state if exists 
     if (State.ContainsKey(App.STATE_KEY)) 
     { 
      //clear prev value 
      State.Remove(App.STATE_KEY); 
     } 
     State.Add(App.STATE_KEY, this.State); 
     base.OnNavigatedFrom(e); 
    } 

    // get state 
    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) 
    { 
     // try to locate the state from previous run 
     if (State.ContainsKey(App.STATE_KEY)) 
     { 
      // return previous state 
      var s = State[App.STATE_KEY] as Info; 
      if (s != null) 
      { 
#if DEBUG 
       Debug.WriteLine("TOMBSTONING EVENT: OnNavigatedTo at {0}", DateTime.Now.ToLongTimeString()); 
#endif 
       this.State = s; 
      } 

     } 

     base.OnNavigatedTo(e); 
    } 

使用这个模式来与枢轴您的网页并保存您的转动控制的最后一个索引。尝试和捕捉块也会很好。

OverviewLifecycle < - 电影