Browse Source

If properties on a markup extension (for example a binding) is modified after the markup extension was set on a property, and these property changes effect how the markup extension can be printed in XAML, the markup extension was not updated properly.

pull/53/merge
Tobias Gummesson 12 years ago committed by Siegfried Pammer
parent
commit
64343cfe57
  1. 22
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs
  2. 33
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs

22
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs

@ -319,8 +319,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
AssertLog(""); AssertLog("");
} }
[Test] void AddBindingWithStaticResourceWhereResourceOnSameElement(bool setBindingPropertiesAfterSet)
public void AddBindingWithStaticResourceWhereResourceOnSameElement()
{ {
DesignItem button = CreateCanvasContext("<Button/>"); DesignItem button = CreateCanvasContext("<Button/>");
DesignItem canvas = button.Parent; DesignItem canvas = button.Parent;
@ -334,10 +333,17 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
resProp.CollectionElements.Add(exampleClassItem); resProp.CollectionElements.Add(exampleClassItem);
DesignItem bindingItem = canvas.Services.Component.RegisterComponentForDesigner(new Binding()); DesignItem bindingItem = canvas.Services.Component.RegisterComponentForDesigner(new Binding());
if (!setBindingPropertiesAfterSet) {
bindingItem.Properties["Path"].SetValue("StringProp"); bindingItem.Properties["Path"].SetValue("StringProp");
bindingItem.Properties["Source"].SetValue(new StaticResourceExtension()); bindingItem.Properties["Source"].SetValue(new StaticResourceExtension());
bindingItem.Properties["Source"].Value.Properties["ResourceKey"].SetValue("bindingSource"); bindingItem.Properties["Source"].Value.Properties["ResourceKey"].SetValue("bindingSource");
}
textBox.Properties[TextBox.TextProperty].SetValue(bindingItem); textBox.Properties[TextBox.TextProperty].SetValue(bindingItem);
if (setBindingPropertiesAfterSet) {
bindingItem.Properties["Path"].SetValue("StringProp");
bindingItem.Properties["Source"].SetValue(new StaticResourceExtension());
bindingItem.Properties["Source"].Value.Properties["ResourceKey"].SetValue("bindingSource");
}
string expectedXaml = "<Button />\n" + string expectedXaml = "<Button />\n" +
"<TextBox>\n" + "<TextBox>\n" +
@ -350,6 +356,18 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
AssertCanvasDesignerOutput(expectedXaml, button.Context); AssertCanvasDesignerOutput(expectedXaml, button.Context);
AssertLog(""); AssertLog("");
} }
[Test]
public void AddBindingWithStaticResourceWhereResourceOnSameElement()
{
AddBindingWithStaticResourceWhereResourceOnSameElement(false);
}
[Test]
public void AddBindingWithStaticResourceWhereResourceOnSameElementAlt()
{
AddBindingWithStaticResourceWhereResourceOnSameElement(true);
}
} }
public class MyMultiConverter : IMultiValueConverter public class MyMultiConverter : IMultiValueConverter

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

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Windows.Markup; using System.Windows.Markup;
using System.Xml; using System.Xml;
using System.Windows.Data; using System.Windows.Data;
@ -144,7 +145,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
internal override void AddNodeTo(XamlProperty property) internal override void AddNodeTo(XamlProperty property)
{ {
if (!UpdateXmlAttribute(true)) { XamlObject holder;
if (!UpdateXmlAttribute(true, out holder)) {
property.AddChildNodeToProperty(element); property.AddChildNodeToProperty(element);
} }
UpdateMarkupExtensionChain(); UpdateMarkupExtensionChain();
@ -156,7 +158,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
XmlAttribute.OwnerElement.RemoveAttribute(XmlAttribute.Name); XmlAttribute.OwnerElement.RemoveAttribute(XmlAttribute.Name);
xmlAttribute = null; xmlAttribute = null;
} else { } else {
if (!UpdateXmlAttribute(false)) { XamlObject holder;
if (!UpdateXmlAttribute(false, out holder)) {
element.ParentNode.RemoveChild(element); element.ParentNode.RemoveChild(element);
} }
} }
@ -168,7 +171,27 @@ namespace ICSharpCode.WpfDesign.XamlDom
//use CanResetValue() //use CanResetValue()
internal void OnPropertyChanged(XamlProperty property) internal void OnPropertyChanged(XamlProperty property)
{ {
UpdateXmlAttribute(false); XamlObject holder;
if (!UpdateXmlAttribute(false, out holder)) {
if (holder != null &&
holder.XmlAttribute != null) {
holder.XmlAttribute.OwnerElement.RemoveAttributeNode(holder.XmlAttribute);
holder.xmlAttribute = null;
holder.ParentProperty.AddChildNodeToProperty(holder.element);
bool isThisUpdated = false;
foreach(XamlObject propXamlObject in holder.Properties.Where((prop) => prop.IsSet).Select((prop) => prop.PropertyValue).OfType<XamlObject>()) {
XamlObject innerHolder;
bool updateResult = propXamlObject.UpdateXmlAttribute(true, out innerHolder);
Debug.Assert(updateResult);
if (propXamlObject == this)
isThisUpdated = true;
}
if (!isThisUpdated)
this.UpdateXmlAttribute(true, out holder);
}
}
UpdateMarkupExtensionChain(); UpdateMarkupExtensionChain();
} }
@ -181,9 +204,9 @@ namespace ICSharpCode.WpfDesign.XamlDom
} }
} }
bool UpdateXmlAttribute(bool force) bool UpdateXmlAttribute(bool force, out XamlObject holder)
{ {
var holder = FindXmlAttributeHolder(); holder = FindXmlAttributeHolder();
if (holder == null && force && IsMarkupExtension) { if (holder == null && force && IsMarkupExtension) {
holder = this; holder = this;
} }

Loading…
Cancel
Save