Browse Source

fixes Bug #408 -> XAML Window Resources doubled

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

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

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

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

@ -21,17 +21,15 @@ 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
{ {
/// <summary> /// <summary>
/// Describes a property on a <see cref="XamlObject"/>. /// Describes a property on a <see cref="XamlObject"/>.
/// </summary> /// </summary>
[DebuggerDisplay("XamlProperty: {PropertyName}")] [DebuggerDisplay("XamlProperty: {PropertyName}")]
public sealed class XamlProperty public sealed class XamlProperty
{ {
XamlObject parentObject; XamlObject parentObject;
@ -315,12 +313,39 @@ 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)
{ {
foreach (XmlNode childNode in node.ChildNodes) { var localName = elementType.Name + "." + propertyName;
if (childNode.LocalName == localName && childNode.NamespaceURI == namespaceURI) var namespaceURI = xamlDocument.GetNamespaceFor(elementType);
return childNode;
} foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.LocalName == localName && childNode.NamespaceURI == namespaceURI)
{
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