首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >WP7旋转控件记住所选项目

WP7旋转控件记住所选项目
EN

Stack Overflow用户
提问于 2010-11-19 10:30:56
回答 1查看 829关注 0票数 1

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

如何更改此行为?这样,如果您在第3个轴心项上,然后转到搜索并返回,则会返回到第3个轴心项。

Pratik

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-11-19 11:28:02

当你按下搜索按钮时,你的应用程序就会被删除(换句话说,应用程序会被停止并尽可能长时间地保存在内存中),.It完全取决于你(开发人员)如何处理它。系统本身只做几件事来获取最后的状态-比如导航到最后一页。你可以把它想象成浏览器中的cookies。如果您按下后退按钮,浏览器将检查是否存在cookie,并从cookie中加载内容。

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

代码语言:javascript
运行
复制
    // 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)
    {
    }

或带有枢轴的页面的事件

代码语言:javascript
运行
复制
    // 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 <-一部电影

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4221615

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档