【问题标题】:WP7 pivotcontrol remember selected itemWP7 pivotcontrol 记住选中的项目
【发布时间】:2010-11-19 02:30:55
【问题描述】:

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

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

普拉提克

【问题讨论】:

    标签: windows-phone-7 pivot


    【解决方案1】:

    当您按下搜索按钮时,您的应用程序将被删除(换句话说,应用程序已停止并尽可能长时间地保存在内存中)。您(开发人员)将如何处理它完全取决于您。系统本身只做一些事情来获得最后的返回状态——比如导航到最后一页。 你可以把它想象成浏览器中的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);
        }
    

    将此模式用于您的页面与枢轴并保存您的枢轴控件的最后一个索引。 try 和 catch 块也会很好。

    Overview Lifecycle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-12
      • 1970-01-01
      相关资源
      最近更新 更多