【问题标题】:Tombstoning in WP7WP7中的墓碑
【发布时间】:2012-06-22 12:30:27
【问题描述】:

我想在我的 WP7 应用程序中实现墓碑,而这个应用程序不是基于 MVVM 模式。任何人都可以向我推荐任何好的例子来实现它。所以我可以使用一些通用类来维护我的应用程序的状态。

【问题讨论】:

    标签: c# silverlight windows-phone-7 tombstoning


    【解决方案1】:

    这里有几个链接可以很好地解释它:

    这个很好地解释了您必须管理的不同状态,包括暂停和墓碑之间的区别。 http://lnluis.wordpress.com/2011/09/25/fast-application-switching-in-windows-phone/

    Shawn Wildermuth 非常棒,并在此视频中向您展示了如何实施。 http://vimeo.com/14311977

    这是一篇详细解释的博文 http://xna-uk.net/blogs/darkgenesis/archive/2010/11/08/there-and-back-again-a-tombstoning-tale-the-return-of-the-application.aspx

    这个来自 Windows Phone 开发者博客: http://windowsteamblog.com/windows_phone/b/wpdev/archive/2010/07/15/understanding-the-windows-phone-application-execution-model-tombstoning-launcher-and-choosers-and-few-more-things-that-are-on-the-way-part-1.aspx

    基本上,当你想要墓碑时,你需要使用 Application_Deactivated 事件将你的变量存储在隔离存储中,并使用 Application_Activated 事件来检索它们。随着 Mango(去年秋天)的出现,您应该在 Application_Activated 中进行测试,以查看应用程序是否处于暂停状态。

    if (!e.IsApplicationInstancePreserved)
      {
        //do stuff to restore from tombstoned
      }
    

    编辑添加另一个示例: 也许这个额外的简单示例会对您有所帮助。 http://dotnet-redzone.blogspot.com/2010/09/windows-phone-7-scrollbar-position.html

    protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)   
    {   
        base.OnNavigatedFrom(e);   
        // Remember scroll offset   
        try   
            {   
                ScrollViewer viewer = ((VisualTreeHelper.GetChild(listBox, 0) as FrameworkElement).FindName("ScrollViewer") as ScrollViewer);   
                State["scrollOffset"] = viewer.VerticalOffset;  
            }  
        catch { }  
    }  
    
    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)  
    {  
        base.OnNavigatedTo(e);  
        object offset;  
        // Return scroll offset  
        if (State.TryGetValue("scrollOffset", out offset))  
            listBox.Loaded += delegate  
            {
                try  
                {  
                    ScrollViewer viewer = ((VisualTreeHelper.GetChild(listBox, 0) as FrameworkElement).FindName("ScrollViewer") as ScrollViewer);  
                    viewer.ScrollToVerticalOffset((double)offset);  
                }  
                catch { }  
            };  
    }
    

    【讨论】:

    • 感谢您提供如此详细的回答。我知道墓碑的基本思想。就我而言,我有 PanromaPage,上面有很多东西,比如“其他项目列表框”上的一个项目上的 Longlist 选择器和“第三个项目”上有很多文本框。所以我想保留我的页面状态,或者你可以说我的控件状态。我很困惑如何实现这一目标
    • 你没有提供很多信息。就像控件是否绑定到某物等。这是另一个非常详细的示例 - 它有帮助吗? blogs.microsoft.co.il/blogs/alex_golesh/archive/2010/07/14/…
    猜你喜欢
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多