开发者

C# XAML serialization of content fields

开发者 https://www.devze.com 2023-02-09 11:17 出处:网络
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

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 {开发者_StackOverflow return textBase.Text;  }
        set { textBase.Text = value; }

    }

I have used XamlServices & XamlWriter but the results is the same, Any solutions ?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消