Browse Source

fixes Bug #408 -> XAML Window Resources doubled

pull/584/head
jogibear9988 11 years ago
parent
commit
ba64d311a7
  1. 12
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SamplesTests.cs
  2. 35
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs

12
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SamplesTests.cs

@ -147,6 +147,18 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
TestLoading(@"<UserControl TestLoading(@"<UserControl
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""> xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<UserControl.Resources>
<ResourceDictionary />
</UserControl.Resources>
</UserControl>");
}
[Test]
public void Resources3()
{
TestLoading(@"<UserControl
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<FrameworkElement.Resources> <FrameworkElement.Resources>
<ResourceDictionary /> <ResourceDictionary />
</FrameworkElement.Resources> </FrameworkElement.Resources>

35
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs

@ -21,10 +21,8 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text;
using System.Xml; using System.Xml;
using System.Windows; using System.Windows;
using System.Windows.Markup;
namespace ICSharpCode.WpfDesign.XamlDom namespace ICSharpCode.WpfDesign.XamlDom
{ {
@ -315,11 +313,38 @@ namespace ICSharpCode.WpfDesign.XamlDom
return this.IsAttached ? this.PropertyTargetType : parentObject.ElementType; return this.IsAttached ? this.PropertyTargetType : parentObject.ElementType;
} }
static XmlNode FindChildNode(XmlNode node, string localName, string namespaceURI) static XmlNode FindChildNode(XmlNode node, Type elementType, string propertyName, XamlDocument xamlDocument)
{
var localName = elementType.Name + "." + propertyName;
var namespaceURI = xamlDocument.GetNamespaceFor(elementType);
foreach (XmlNode childNode in node.ChildNodes)
{ {
foreach (XmlNode childNode in node.ChildNodes) {
if (childNode.LocalName == localName && childNode.NamespaceURI == namespaceURI) if (childNode.LocalName == localName && childNode.NamespaceURI == namespaceURI)
{
return childNode; return childNode;
}
}
var type = elementType.BaseType;
namespaceURI = xamlDocument.GetNamespaceFor(type);
while (type != typeof(object))
{
if (type.GetProperty(propertyName) == null)
break;
localName = type.Name + "." + propertyName;
foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.LocalName == localName && childNode.NamespaceURI == namespaceURI)
{
return childNode;
}
}
type = type.BaseType;
} }
return null; return null;
@ -335,7 +360,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (this.IsCollection) { if (this.IsCollection) {
if (IsNodeCollectionForThisProperty(newChildNode)) { if (IsNodeCollectionForThisProperty(newChildNode)) {
Type propertyElementType = GetPropertyElementType(); Type propertyElementType = GetPropertyElementType();
XmlNode parentNode = FindChildNode(parentObject.XmlElement, propertyElementType.Name + "." + this.PropertyName, parentObject.OwnerDocument.GetNamespaceFor(propertyElementType)); XmlNode parentNode = FindChildNode(parentObject.XmlElement, propertyElementType, this.PropertyName, parentObject.OwnerDocument);
if (parentNode == null) { if (parentNode == null) {
parentNode = CreatePropertyElement(); parentNode = CreatePropertyElement();

Loading…
Cancel
Save