如何使用.net Metro风格应用程序的ApplicationStateModel类?

时间:2012-01-13 21:44:43

标签: c# microsoft-metro

我想在metro风格的应用程序收到暂停事件时保存应用程序状态。

我在this link中找到了下面的代码,但我没有在.Net中找到类ApplicationStateModel:

public App()
{
   InitializeComponent();
   this.Suspending += new SuspendingEventHandler(App_Suspending);
   this.Resuming += new Windows.UI.Xaml.EventHandler(App_Resuming);
}

void App_Resuming(object sender, object e)
{
   // Write code to update ui only for items that are outdated.
   // This is resume from suspended state, so it does not lose any data
}

async void App_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
{
   // Write code to store data so that when the application is terminated the state can be recovered.
   // Allowed only 5 seconds to do the storage
   SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral();
   await **ApplicationStateModel**.SaveAllApplicationDataAsync();
   await ApplicationStateModel.SaveSessionStateAsync();
   deferral.Complete();
}

1 个答案:

答案 0 :(得分:0)

您可以使用Windows.Storage.ApplicationData保存本地设置。 请查看保存设置的正在运行的应用的Sample SDK app