简体   繁体   English

如何在挂起Windows Phone 8.1 rt xaml C时保存ui状态

[英]how to save ui state on suspending Windows phone 8.1 rt xaml c#

I found basic pages for suspend an app on windows phone 8.1 but I didn't find how to save UI state on suspending. 我在Windows Phone 8.1上找到了挂起应用程序的基本页面,但没有找到如何在挂起时保存UI状态。 I'm making an audio player app which have in mainpage a grid which I display or not and it contains media buttons, thumbnail, slider etc. When app is forced to suspend itself and I reopen it, it restart like first opening so it lose the app state. 我正在制作一个音频播放器应用程序,该应用程序在主页上有一个不显示或不显示的网格,它包含媒体按钮,缩略图,滑块等。当应用程序被迫暂停自身并重新打开时,它像第一次打开一样重新启动,因此丢失应用状态。 How can I save all app state? 如何保存所有应用状态?

Bind all relevant UI States to some object (aka ViewModel ) and serialize these states upon suspending. 将所有相关的UI状态绑定到某个对象(也称为ViewModel ),并在挂起时序列化这些状态。

The basic page template also includes methods like SaveState and LoadState including a serialized dictionary, where you can store those values. 基本页面模板还包括诸如SaveStateLoadState类的方法,其中包括序列化的字典,您可以在其中存储这些值。

Another option is to set the page's NavigationCacheMode to Enabled or Required . 另一个选项是将页面的NavigationCacheMode设置为EnabledRequired This will keep the page in memory until your app is terminated. 这会将页面保留在内存中,直到您的应用终止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM