Windows Phone上的隔离存储(IsolatedStorageSettings)限制

时间:2012-04-20 11:12:25

标签: c# windows-phone-7

我的应用程序中有键值IsolatedStorage,它包含4个变量:2个双精度,1个bool和1个类对象的ObservableCollection。 当我将ObservableCollection设置为设置并将其保存为此

settings["PlaceMarks"] = PlaceMarks;

它覆盖了我的bool var,并在下次启动时得到“未找到密钥”异常

如果我写这个设置类似字符串或数字

settings["PlaceMarks"] = "string";

一切都好。我的集合只有三个简单类的实例。 所以这是我的问题,为什么我的价值消失了?可能是我不知道的IsolatedStorageSettings的一些限制

2 个答案:

答案 0 :(得分:3)

您是否已将Observeable Collection中的类标记为Serializableable?

ObservableCollection本身未标记为可序列化。 http://msdn.microsoft.com/en-us/library/ms668604(v=vs.95).aspx

我建议您尝试使用List

答案 1 :(得分:1)

只有可序列化的对象(不是ObservableCollection的情况)可以保存在IsolatedStorageSettings中。

在保存IsolatedStorageSettings之前,使用DataContractSerializer序列化对象。

https://stackoverflow.com/a/7417049/358596