[英]How to serialize a type that inherits WPF's Paragraph?
I sub-classed the WPF
's Paragraph
as follows, and now I want to serialize and deserialize it, including the additional data. 我对WPF
的Paragraph
子分类,现在,我想对其进行序列化和反序列化,包括其他数据。
xamlString = XamlWriter.Save(_richTextBox.Document);
doesn't do the trick - the extended data is omitted. 不能解决问题-省略扩展数据。
There's is way to tell the XamlWriter
to include this extra data ? 有办法告诉XamlWriter
包含这些额外的数据吗?
Here is the extended data: 这是扩展数据:
[ContentProperty("Inlines")]
public class ExParagraph : Paragraph
{
public ParagraphMetaData MetaData = new ParagraphMetaData();
}
[ContentProperty("Inlines")]
public class ParagraphMetaData {
private Guid _updaterParagraphUniqueId;
public Guid UpdaterParagraphUniqueId {
get { return _updaterParagraphUniqueId; }
set {
_updaterParagraphUniqueId = value;
IsUpdaterParagraph = value != default(Guid);
}
}
public bool IsUpdaterParagraph { get; private set; }
public string Name;
public bool DoNotToggleColor;
}
Thanks to responders: the fields must be r/w properties 多亏了响应者:这些字段必须是r / w属性
In addition, the [ContentProperty("Inlines")]
was the root problem - it prevented the serialization of the sub-classed Paragraph
此外, [ContentProperty("Inlines")]
是根本问题-它阻止了对子类Paragraph
的序列化
Fields are not serialized, only properties. 字段未序列化,仅属性。 They also must be read-write properties, not read-only. 它们还必须是读写属性,而不是只读属性。 This post is pretty old but most of the information still applies: 这篇文章很老,但是大多数信息仍然适用:
http://blogs.msdn.com/b/mikehillberg/archive/2006/09/16/xamlwriter.aspx http://blogs.msdn.com/b/mikehillberg/archive/2006/09/16/xamlwriter.aspx
Edit: also read http://msdn.microsoft.com/en-us/library/ms754193.aspx for additional information. 编辑:另请阅读http://msdn.microsoft.com/en-us/library/ms754193.aspx 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.