【发布时间】:2012-06-22 12:30:27
【问题描述】:
我想在我的 WP7 应用程序中实现墓碑,而这个应用程序不是基于 MVVM 模式。任何人都可以向我推荐任何好的例子来实现它。所以我可以使用一些通用类来维护我的应用程序的状态。
【问题讨论】:
标签: c# silverlight windows-phone-7 tombstoning
我想在我的 WP7 应用程序中实现墓碑,而这个应用程序不是基于 MVVM 模式。任何人都可以向我推荐任何好的例子来实现它。所以我可以使用一些通用类来维护我的应用程序的状态。
【问题讨论】:
标签: c# silverlight windows-phone-7 tombstoning
这里有几个链接可以很好地解释它:
这个很好地解释了您必须管理的不同状态,包括暂停和墓碑之间的区别。 http://lnluis.wordpress.com/2011/09/25/fast-application-switching-in-windows-phone/
Shawn Wildermuth 非常棒,并在此视频中向您展示了如何实施。 http://vimeo.com/14311977
这个来自 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 { }
};
}
【讨论】: