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. 28
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs
  2. 37
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs

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

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

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

@ -5,6 +5,7 @@ using System; @@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Windows.Markup;
using System.Xml;
using System.Windows.Data;
@ -143,8 +144,9 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -143,8 +144,9 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
internal override void AddNodeTo(XamlProperty property)
{
if (!UpdateXmlAttribute(true)) {
{
XamlObject holder;
if (!UpdateXmlAttribute(true, out holder)) {
property.AddChildNodeToProperty(element);
}
UpdateMarkupExtensionChain();
@ -156,7 +158,8 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -156,7 +158,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
XmlAttribute.OwnerElement.RemoveAttribute(XmlAttribute.Name);
xmlAttribute = null;
} else {
if (!UpdateXmlAttribute(false)) {
XamlObject holder;
if (!UpdateXmlAttribute(false, out holder)) {
element.ParentNode.RemoveChild(element);
}
}
@ -167,8 +170,28 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -167,8 +170,28 @@ namespace ICSharpCode.WpfDesign.XamlDom
//TODO: reseting path property for binding doesn't work in XamlProperty
//use CanResetValue()
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();
}
@ -181,9 +204,9 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -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) {
holder = this;
}

Loading…
Cancel
Save