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

发布于 2024-12-26 21:21:05 字数 1085 浏览 4 评论 0原文

我想在 Metro 风格应用程序收到挂起事件时保存应用程序状态。

我在此链接中找到 下面的代码,但我在.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();
}

I want to save the application state when an metro style app receive the suspend event.

I found in this link the code below, but I don´t find in .Net the class 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();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稍尽春風 2025-01-02 21:21:05

您可以使用 Windows.Storage.ApplicationData 保存本地设置。
查看示例 SDK 应用,了解正在运行的应用程序,该应用程序可节省您的设置。

You can use Windows.Storage.ApplicationData to save local settings.
Take a look at the Sample SDK app for a running app that saves your settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文