C# XAML serialization of content fields
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.
精彩评论