WP7 pivotcontrol记住所选项目

时间:2010-11-19 02:30:56

标签: windows-phone-7 pivot

在Windows Phone 7枢轴控制模板项目中,如果您从特定枢轴项目转到搜索页面并在电话上选择回来,则枢轴控制页面不会记住所选项目。它总是回到枢轴控制的第一项。

如何更改此行为,如果您在第3个支点项目上,然后转到搜索并回击,则返回第3个支点项目。

PRATIK

1 个答案:

答案 0 :(得分:3)

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

将此模式用于带有数据透视表的页面,并保存数据透视控件的最后一个索引。尝试和捕捉块也会很好。

Overview Lifecycle< - 电影