简体   繁体   English

XML序列化用于隔离存储的图钉

[英]XML Serialize a Pushpin for Isolated Storage

I'm studying Isolated Storage and have successfully stored objects in it, now I'm trying to store a Pushpin in isolated storage. 我正在研究隔离存储,并且已经成功地在其中存储了对象,现在我试图将图钉存储在隔离存储中。 I straight up copied the method I used to serialize an object and store it. 我直接复制了用于序列化对象并存储它的方法。

using (IsolatedStorageFileStream stream = IsolatedStorageFile
    .GetUserStoreForApplication().OpenFile("home.xml", FileMode.Create))
{
    XmlSerializer serializer = new XmlSerializer(typeof(List<Pushpin>));
    using (XmlWriter writer = XmlWriter.Create(stream, settings))
    {
        serializer.Serialize(stream, p);
    }
}

Where p is a pushpin, the error it's throwing is 其中p是图钉,它引发的错误是

There was an error reflecting type Pushpin. 反映类型图钉的错误。

I could cheaply create a class to store Lat/Long, store that and recreate the pushpins, but I'd like to understand/figure out why I can't serialize this object. 我可以廉价地创建一个类来存储纬度/经度,存储纬度并重新创建图钉,但是我想了解/弄清楚为什么我不能序列化此对象。

My end goal is to permanently store a list of pushpins so users can track journeys they've been on - just something to help me learn Bing maps and Isolated Storage. 我的最终目标是永久存储图钉列表,以便用户可以跟踪他们曾经去过的旅程-只是帮助我学习Bing地图和隔离存储的工具。

The Pushpin class is not designed to be serializable and thus the issue you are getting. Pushpin类并非设计为可序列化的,因此会遇到问题。 The best option is to create an object that stores the information for the pushpin and to regenerate the pushpins from this data. 最好的选择是创建一个存储图钉信息的对象,并从此数据重新生成图钉。 If you are using MVVM then store your view model for the pushpin. 如果使用的是MVVM,则存储图钉的视图模型。

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

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