Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit bb4a661

Browse files
committed
Fixed so its possible to use MultiBinding and PriorityBinding on a DesignItemProperty and that it writes as expected to XAML.
1 parent 2af3fcb commit bb4a661

4 files changed

Lines changed: 72 additions & 15 deletions

File tree

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTestHelper.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
2121
/// </summary>
2222
public class ModelTestHelper
2323
{
24+
public const string DesignerTestsNamespace = "clr-namespace:ICSharpCode.WpfDesign.Tests.Designer;assembly=ICSharpCode.WpfDesign.Tests";
25+
2426
protected StringBuilder log;
2527

2628
protected XamlDesignContext CreateContext(string xaml)
@@ -40,7 +42,8 @@ protected DesignItem CreateCanvasContext(string xaml)
4042
{
4143
XamlDesignContext context = CreateContext(@"<Canvas
4244
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
43-
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
45+
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
46+
xmlns:t=""" + DesignerTestsNamespace + @""">
4447
" + xaml + "</Canvas>");
4548
Canvas canvas = (Canvas)context.RootItem.Component;
4649
DesignItem canvasChild = context.Services.Component.GetDesignItem(canvas.Children[0]);
@@ -54,7 +57,8 @@ protected void AssertCanvasDesignerOutput(string expectedXaml, DesignContext con
5457
expectedXaml =
5558
"<?xml version=\"1.0\" encoding=\"utf-16\"?>\n" +
5659
("<Canvas xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" " +
57-
"xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">\n" + expectedXaml.Trim())
60+
"xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" " +
61+
"xmlns:t=\"" + DesignerTestsNamespace + "\">\n" + expectedXaml.Trim())
5862
.Replace("\r", "").Replace("\n", "\n ")
5963
+ "\n</Canvas>";
6064

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

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
22
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
33

4-
using System;
5-
using System.Text;
6-
using System.IO;
7-
using System.Xml;
8-
using System.Diagnostics;
9-
using System.Windows;
10-
using System.Windows.Controls;
11-
using NUnit.Framework;
12-
using ICSharpCode.WpfDesign.Designer;
13-
using ICSharpCode.WpfDesign.Designer.Xaml;
14-
using ICSharpCode.WpfDesign.Designer.Services;
4+
using System;
5+
using System.Text;
6+
using System.IO;
7+
using System.Xml;
8+
using System.Diagnostics;
9+
using System.Windows;
10+
using System.Windows.Controls;
11+
using System.Windows.Data;
12+
using NUnit.Framework;
13+
using ICSharpCode.WpfDesign.Designer;
14+
using ICSharpCode.WpfDesign.Designer.Xaml;
15+
using ICSharpCode.WpfDesign.Designer.Services;
1516

1617
namespace ICSharpCode.WpfDesign.Tests.Designer
1718
{
@@ -235,5 +236,52 @@ public void ClearImplicitChildCollection()
235236
"</Canvas>", canvas.Context);
236237
AssertLog("");
237238
}
239+
240+
[Test]
241+
public void AddMultiBindingToTextBox()
242+
{
243+
DesignItem button = CreateCanvasContext("<Button/>");
244+
DesignItem canvas = button.Parent;
245+
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
246+
canvas.Properties["Children"].CollectionElements.Add(textBox);
247+
248+
textBox.Properties[TextBox.TextProperty].SetValue(new MultiBinding());
249+
DesignItem multiBindingItem = textBox.Properties[TextBox.TextProperty].Value;
250+
multiBindingItem.Properties["Converter"].SetValue(new MyMultiConverter());
251+
252+
DesignItemProperty bindingsProp = multiBindingItem.ContentProperty;
253+
Assert.IsTrue(bindingsProp.IsCollection);
254+
Assert.AreEqual(bindingsProp.Name, "Bindings");
255+
256+
DesignItem bindingItem = canvas.Services.Component.RegisterComponentForDesigner(new Binding());
257+
bindingItem.Properties["Path"].SetValue("SomeProperty");
258+
bindingsProp.CollectionElements.Add(bindingItem);
259+
260+
string expectedXaml = "<Button />\n" +
261+
"<TextBox>\n" +
262+
" <MultiBinding>\n" +
263+
" <MultiBinding.Converter>\n" +
264+
" <t:MyMultiConverter />\n" +
265+
" </MultiBinding.Converter>\n" +
266+
" <Binding Path=\"SomeProperty\" />\n" +
267+
" </MultiBinding>\n" +
268+
"</TextBox>";
269+
270+
AssertCanvasDesignerOutput(expectedXaml, button.Context);
271+
AssertLog("");
272+
}
273+
}
274+
275+
public class MyMultiConverter : IMultiValueConverter
276+
{
277+
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
278+
{
279+
return null;
280+
}
281+
282+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
283+
{
284+
return new object[targetTypes.Length];
285+
}
238286
}
239287
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public static class MarkupExtensionPrinter
1818
/// </summary>
1919
public static bool CanPrint(XamlObject obj)
2020
{
21+
if (obj.ElementType == typeof(System.Windows.Data.MultiBinding) ||
22+
obj.ElementType == typeof(System.Windows.Data.PriorityBinding)) {
23+
return false;
24+
}
25+
2126
return true;
2227
}
2328

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ internal void OnPropertyChanged(XamlProperty property)
188188
void UpdateMarkupExtensionChain()
189189
{
190190
var obj = this;
191-
while (obj != null && obj.IsMarkupExtension) {
191+
while (obj != null && obj.IsMarkupExtension && obj.ParentProperty != null) {
192192
obj.ParentProperty.UpdateValueOnInstance();
193193
obj = obj.ParentObject;
194194
}
@@ -445,7 +445,7 @@ public void SetXamlAttribute(string name, string value)
445445

446446
void CreateWrapper()
447447
{
448-
if (Instance is Binding) {
448+
if (Instance is BindingBase) {
449449
wrapper = new BindingWrapper();
450450
} else if (Instance is StaticResourceExtension) {
451451
wrapper = new StaticResourceWrapper();

0 commit comments

Comments
 (0)