1

http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj735579%28v=vs.105%29.aspx 根据我在 windows phone 8 中使用快速恢复时的文档,我可以从主瓷砖。

但是当我的应用程序被墓碑化时,例如,mainPage 可以导航到->pageA 可以导航到-> PageB,我从 PageA 停用了该应用程序,然后该应用程序被墓碑化了,当我单击导航到 PageB 的 Tile 时,奇怪的是应用程序返回到 Page A 。

如何解决这个问题?

4

1 回答 1

1

It sounds like you are not saving the application state before it is tombstoned. There are 4 events that are fired for preserving application state:

These are related to completely closing and reopening the application (eg: Phone restart)

  • Application_Launching
  • Application_Closing

These are related to tombstoning (task switching)

  • Application_Activated
  • Application_Deactivated

It sounds like what you need is the second one relating to activating / deactivating. These methods are placed in the Applications *.cs file and allow you to preserve and reinstate the ViewModel when tombstoning.

This is an 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;
  }
}
于 2012-12-07T07:35:22.257 回答