内容字段的 C# XAML 序列化
我有一个基本的文本绘制类,其中包含“文本”作为“内容”属性,并且需要将其序列化为属性,但它返回为普通文本元素,例如
[ContentProperty("Text")]
public class TextElement
{ [XmlAttribute("Text")]
public string Text
{
get { return textBase.Text; }
set { textBase.Text = value; }
}
我使用过的 XamlServices & 示例。 XamlWriter 但结果是相同的,有解决方案吗?
I have a basic text drawing class that contains the "Text" as a "content" property as well as it needs to be serialized as an ATTRIBUTE, but rather it returns as a normal text element like Sample
[ContentProperty("Text")]
public class TextElement
{ [XmlAttribute("Text")]
public string Text
{
get { return textBase.Text; }
set { textBase.Text = value; }
}
I have used XamlServices & XamlWriter but the results is the same, Any solutions ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 DesignerSerializationOptionsAttribute 装饰 Text 属性:
[DesignerSerializationOptions(DesignerSerializationOptions.SerializeAsAttribute)]
请参阅:
http://msdn.microsoft.com/en-us/library/system.windows.markup.designerserializationoptionsattribute.aspx
XmlAttributeAttribute 仅影响 XmlSerializer 序列化。
Try decorating the Text property with the DesignerSerializationOptionsAttribute:
[DesignerSerializationOptions(DesignerSerializationOptions.SerializeAsAttribute)]
See:
http://msdn.microsoft.com/en-us/library/system.windows.markup.designerserializationoptionsattribute.aspx
The XmlAttributeAttribute only affects XmlSerializer serialization.