[英]Isolated Storage - Windows Phone 8
我的项目中有两页。 第一页将创建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有一个字符串“ points”,但里面没有任何内容。 它仅具有[“ key”],但没有[value]。
问题已经解决了!!
MyPoint对象在构造函数中具有Ellipse。 IsolatedStorage引发有关UIElement的异常,无法序列化。
现在一切正常!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.