问题描述
我有一个包含5个属性的类:3个字符串,1个Brush 和1个DateTime,我正在尝试找到保存此类实例的方法,但我不断收到序列化错误?
Hi, I have a class which contains 5 properties: 3 strings, one Brush and one DateTime, and i'm trying to find a way to save an instance of this class but I keep getting serialization errors?
此外,我想以这样的方式保存它,以便我可以获取此类的所有已保存实例并将其显示在gridview中。 (顺便说一下这是我正在谈论的地铁风格的应用程序)
Also I want to save it in such a way so that I can get all saved instances of this class and display them in a gridview. (btw this is a metro style app i'm talking about)
如果有人能解释如何做到这一点,我将非常感激!
If someone could explain how to do this I would be extremely grateful!
谢谢
Dominic Ayre
Dominic Ayre
推荐答案
我所指的方法是:
/// <summary>
/// Save the current <see cref="SessionState"/>. Any <see cref="Frame"/> instances
/// registered with <see cref="RegisterFrame"/> will also preserve their current
/// navigation stack, which in turn gives their active <see cref="Page"/> an opportunity
/// to save its state.
/// </summary>
/// <returns>An asynchronous task that reflects when session state has been saved.</returns>
public static async Task SaveAsync()
/// <summary>
/// Restores previously saved <see cref="SessionState"/>. Any <see cref="Frame"/> instances
/// registered with <see cref="RegisterFrame"/> will also restore their prior navigation
/// state, which in turn gives their active <see cref="Page"/> an opportunity restore its
/// state.
/// </summary>
/// <returns>An asynchronous task that reflects when session state has been read. The
/// content of <see cref="SessionState"/> should not be relied upon until this task
/// completes.</returns>
public static async Task RestoreAsync()
但是,只需确保将类型包含在暂停管理器中的KnowTypes(List< Type>)属性中。
However, just make sure to include your type in the KnowTypes (List<Type>) property in the suspension manager.
这篇关于如何保存类的实例并再次读取它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!