Browse Source

Fixed bug; CanPrint was only checked for the first property using nested markup extension.

pull/617/head
gumme 12 years ago
parent
commit
8d47f04678
  1. 32
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs
  2. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/MarkupExtensionPrinter.cs

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

@ -596,7 +596,13 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox()); DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
canvas.Properties["Children"].CollectionElements.Add(textBox); canvas.Properties["Children"].CollectionElements.Add(textBox);
DesignItemProperty resProp = textBox.Properties.GetProperty("Resources"); DesignItemProperty resProp = button.Properties.GetProperty("Resources");
Assert.IsTrue(resProp.IsCollection);
DesignItem dummyItem = canvas.Services.Component.RegisterComponentForDesigner(new ExampleClass());
dummyItem.Key = "dummy";
resProp.CollectionElements.Add(dummyItem);
resProp = textBox.Properties.GetProperty("Resources");
Assert.IsTrue(resProp.IsCollection); Assert.IsTrue(resProp.IsCollection);
DesignItem exampleClassItem = canvas.Services.Component.RegisterComponentForDesigner(new ExampleClass()); DesignItem exampleClassItem = canvas.Services.Component.RegisterComponentForDesigner(new ExampleClass());
exampleClassItem.Key = "bindingSource"; exampleClassItem.Key = "bindingSource";
@ -605,23 +611,33 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
DesignItem bindingItem = canvas.Services.Component.RegisterComponentForDesigner(new Binding()); DesignItem bindingItem = canvas.Services.Component.RegisterComponentForDesigner(new Binding());
if (!setBindingPropertiesAfterSet) { if (!setBindingPropertiesAfterSet) {
bindingItem.Properties["Path"].SetValue("StringProp"); bindingItem.Properties["Path"].SetValue("StringProp");
// Using resource "dummy" before "bindingSource" to enable test where not the first set property will require element-style print of the binding
bindingItem.Properties["ConverterParameter"].SetValue(new StaticResourceExtension());
bindingItem.Properties["ConverterParameter"].Value.Properties["ResourceKey"].SetValue("dummy");
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) { if (setBindingPropertiesAfterSet) {
bindingItem.Properties["Path"].SetValue("StringProp"); bindingItem.Properties["Path"].SetValue("StringProp");
// Using resource "dummy" before "bindingSource" to enable test where not the first set property will require element-style print of the binding
bindingItem.Properties["ConverterParameter"].SetValue(new StaticResourceExtension());
bindingItem.Properties["ConverterParameter"].Value.Properties["ResourceKey"].SetValue("dummy");
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");
} }
string expectedXaml = "<Button />\n" + const string expectedXaml = "<Button>\n" +
"<TextBox>\n" + " <Button.Resources>\n" +
" <TextBox.Resources>\n" + " <t:ExampleClass x:Key=\"dummy\" />\n" +
" <t:ExampleClass x:Key=\"bindingSource\" />\n" + " </Button.Resources>\n" +
" </TextBox.Resources>\n" + "</Button>\n" +
" <Binding Path=\"StringProp\" Source=\"{StaticResource bindingSource}\" />\n" + "<TextBox>\n" +
"</TextBox>"; " <TextBox.Resources>\n" +
" <t:ExampleClass x:Key=\"bindingSource\" />\n" +
" </TextBox.Resources>\n" +
" <Binding Path=\"StringProp\" ConverterParameter=\"{StaticResource dummy}\" Source=\"{StaticResource bindingSource}\" />\n" +
"</TextBox>";
AssertCanvasDesignerOutput(expectedXaml, button.Context); AssertCanvasDesignerOutput(expectedXaml, button.Context);
AssertLog(""); AssertLog("");

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/MarkupExtensionPrinter.cs

@ -137,8 +137,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
var xamlObject = value as XamlObject; var xamlObject = value as XamlObject;
if (xamlObject == null || !xamlObject.IsMarkupExtension) if (xamlObject == null || !xamlObject.IsMarkupExtension)
return false; return false;
else else if (!CanPrint(xamlObject, true, nonMarkupExtensionParent))
return CanPrint(xamlObject, true, nonMarkupExtensionParent); return false;
} }
} }

Loading…
Cancel
Save