我的项目中有两页。第一页即将创建MyPoint对象,然后将其添加到List,最后将其保存到Isolated Storage,如下所示:
IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
积分课程:
public class MyPoint
{
public Ellipse Point { get; set; }
public string Tag { get; set; }
public GeoCoordinate Coords { get; set; }
public string City { get; set; }
public string PostalCode { get; set; }
public MyPoint() { }
public MyPoint(Ellipse point, GeoCoordinate cords, string tag, string city, string postalCode)
{
this.Point = point;
this.Coords = cords;
this.Tag = tag;
this.City = city;
this.PostalCode = postalCode;
}
}
保存到隔离存储方法:
private void SaveAppSettings()
{
try
{
appSettings.Remove("points");
}
catch { }
try
{
appSettings.Add("points", this.points);
appSettings.Save(); // this throws an Exception
}
catch { };
}
Secound的页面加载方法
try
{
List<MyPoint> points = (List<MyPoint>)appSettings["points"];
foreach (MyPoint p in points)
{
source.Add(new PointsBook(p.Tag, p.Coords, p.City, p.PostalCode));
}
}
重点是
appSettings.Save()有一个例外,即使我评论这一行都是有效的。我已经保存了点数,我可以在这两页中阅读它们。
问题是当我关闭应用程序时,我的appSetting有一个字符串&#34; points&#34;但里面没什么。它只有[&#34;键&#34;]但没有[值]。
答案 0 :(得分:0)
问题解决了!!
MyPoint对象在构造函数中有Ellipse。 IsolatedStorage引发了关于UIElement的异常无法序列化。
现在一切正常!