Browse Source

Fixed bug; Only sets the inner text of an XML element if the element type defines a Content property.

pull/53/merge
gumme 12 years ago committed by Siegfried Pammer
parent
commit
95e36a6eef
  1. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs
  2. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs

@ -169,9 +169,12 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -169,9 +169,12 @@ namespace ICSharpCode.WpfDesign.XamlDom
XmlElement xml = _xmlDoc.CreateElement(elementType.Name, GetNamespaceFor(elementType));
if (hasStringConverter) {
if (hasStringConverter &&
XamlObject.GetContentPropertyName(elementType) != null)
{
xml.InnerText = c.ConvertToInvariantString(instance);
}
return new XamlObject(this, xml, elementType, instance);
}

20
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs

@ -32,10 +32,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -32,10 +32,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
this.elementType = elementType;
this.instance = instance;
var contentAttrs = elementType.GetCustomAttributes(typeof(ContentPropertyAttribute), true) as ContentPropertyAttribute[];
if (contentAttrs != null && contentAttrs.Length > 0) {
this.contentPropertyName = contentAttrs[0].Name;
}
this.contentPropertyName = GetContentPropertyName(elementType);
ServiceProvider = new XamlObjectServiceProvider(this);
CreateWrapper();
@ -130,6 +127,21 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -130,6 +127,21 @@ namespace ICSharpCode.WpfDesign.XamlDom
return newElement;
}
/// <summary>
/// Gets the name of the content property for the specified element type, or null if not available.
/// </summary>
/// <param name="elementType">The element type to get the content property name for.</param>
/// <returns>The name of the content property for the specified element type, or null if not available.</returns>
internal static string GetContentPropertyName(Type elementType)
{
var contentAttrs = elementType.GetCustomAttributes(typeof(ContentPropertyAttribute), true) as ContentPropertyAttribute[];
if (contentAttrs != null && contentAttrs.Length > 0) {
return contentAttrs[0].Name;
}
return null;
}
internal override void AddNodeTo(XamlProperty property)
{
if (!UpdateXmlAttribute(true)) {

Loading…
Cancel
Save