diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs index a5a76efbcf..3bfdf6fe24 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs @@ -97,7 +97,7 @@ namespace ICSharpCode.WpfDesign.XamlDom XmlAttribute xmlAttribute; - internal XmlAttribute XmlAttribute { + internal XmlAttribute XmlAttribute { get { return xmlAttribute; } set { xmlAttribute = value; @@ -105,9 +105,26 @@ namespace ICSharpCode.WpfDesign.XamlDom } } - static XmlElement VirtualAttachTo(XmlElement e, XmlElement target) + string GetPrefixOfNamespace(string ns, XmlElement target) { - var prefix = target.GetPrefixOfNamespace(e.NamespaceURI); + var prefix = target.GetPrefixOfNamespace(ns); + if (!string.IsNullOrEmpty(prefix)) + return prefix; + var obj = this; + while (obj != null) + { + prefix = obj.XmlElement.GetPrefixOfNamespace(ns); + if (!string.IsNullOrEmpty(prefix)) + return prefix; + obj = obj.ParentObject; + } + return null; + } + + XmlElement VirtualAttachTo(XmlElement e, XmlElement target) + { + var prefix = GetPrefixOfNamespace(e.NamespaceURI, target); + XmlElement newElement = e.OwnerDocument.CreateElement(prefix, e.LocalName, e.NamespaceURI); foreach (XmlAttribute a in target.Attributes) { @@ -153,7 +170,7 @@ namespace ICSharpCode.WpfDesign.XamlDom } internal override void RemoveNodeFromParent() - { + { if (XmlAttribute != null) { XmlAttribute.OwnerElement.RemoveAttribute(XmlAttribute.Name); xmlAttribute = null; @@ -162,7 +179,7 @@ namespace ICSharpCode.WpfDesign.XamlDom if (!UpdateXmlAttribute(false, out holder)) { element.ParentNode.RemoveChild(element); } - } + } //TODO: PropertyValue still there //UpdateMarkupExtensionChain(); } @@ -174,7 +191,7 @@ namespace ICSharpCode.WpfDesign.XamlDom XamlObject holder; if (!UpdateXmlAttribute(false, out holder)) { if (holder != null && - holder.XmlAttribute != null) { + holder.XmlAttribute != null) { holder.XmlAttribute.OwnerElement.RemoveAttributeNode(holder.XmlAttribute); holder.xmlAttribute = null; holder.ParentProperty.AddChildNodeToProperty(holder.element); @@ -201,7 +218,7 @@ namespace ICSharpCode.WpfDesign.XamlDom while (obj != null && obj.IsMarkupExtension && obj.ParentProperty != null) { obj.ParentProperty.UpdateValueOnInstance(); obj = obj.ParentObject; - } + } } bool UpdateXmlAttribute(bool force, out XamlObject holder) @@ -280,7 +297,7 @@ namespace ICSharpCode.WpfDesign.XamlDom /// public string ContentPropertyName { get { - return contentPropertyName; + return contentPropertyName; } } @@ -293,7 +310,7 @@ namespace ICSharpCode.WpfDesign.XamlDom throw new ArgumentNullException("propertyName"); // if (propertyName == ContentPropertyName) -// return +// return foreach (XamlProperty p in properties) { if (!p.IsAttached && p.PropertyName == propertyName) @@ -379,7 +396,7 @@ namespace ICSharpCode.WpfDesign.XamlDom } object ProvideValue() - { + { if (wrapper != null) { return wrapper.ProvideValue(); }