【问题标题】:Windows phone 8 Fast Resume when TombstonedWindows phone 8 墓碑删除时快速恢复
【发布时间】:2023-03-04 07:06:04
【问题描述】:
【问题讨论】:
标签:
windows
windows-phone-7
windows-phone-8
【解决方案1】:
听起来您没有在应用程序状态被墓碑之前保存它。为保留应用程序状态会触发 4 个事件:
这些与完全关闭和重新打开应用程序有关(例如:手机重启)
- Application_Launching
- Application_Closing
这些与墓碑(任务切换)有关
- Application_Activated
- Application_Deactivated
听起来您需要的是与激活/停用相关的第二个。这些方法放置在 Applications *.cs 文件中,允许您在删除时保留和恢复 ViewModel。
这是example:
private readonly string ModelKey = "Key";
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
PhoneApplicationService.Current.State[ModelKey] = ViewModel;
}
private void Application_Activated(object sender, ActivatedEventArgs e)
{
if (PhoneApplicationService.Current.State.ContainsKey(ModelKey))
{
ViewModel = PhoneApplicationService.Current.State[ModelKey] as FeedViewModel;
RootFrame.DataContext = ViewModel;
}
}