Browse Source

Fixed so its possible to use MultiBinding and PriorityBinding on a DesignItemProperty and that it writes as expected to XAML.

pull/53/merge
Tobias Gummesson 12 years ago committed by Siegfried Pammer
parent
commit
ccda46b899
  1. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTestHelper.cs
  2. 70
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs
  3. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/MarkupExtensionPrinter.cs
  4. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs

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

@ -21,6 +21,8 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -21,6 +21,8 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
/// </summary>
public class ModelTestHelper
{
public const string DesignerTestsNamespace = "clr-namespace:ICSharpCode.WpfDesign.Tests.Designer;assembly=ICSharpCode.WpfDesign.Tests";
protected StringBuilder log;
protected XamlDesignContext CreateContext(string xaml)
@ -40,7 +42,8 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -40,7 +42,8 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
{
XamlDesignContext context = CreateContext(@"<Canvas
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:t=""" + DesignerTestsNamespace + @""">
" + xaml + "</Canvas>");
Canvas canvas = (Canvas)context.RootItem.Component;
DesignItem canvasChild = context.Services.Component.GetDesignItem(canvas.Children[0]);
@ -54,7 +57,8 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -54,7 +57,8 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
expectedXaml =
"<?xml version=\"1.0\" encoding=\"utf-16\"?>\n" +
("<Canvas xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" " +
"xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">\n" + expectedXaml.Trim())
"xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" " +
"xmlns:t=\"" + DesignerTestsNamespace + "\">\n" + expectedXaml.Trim())
.Replace("\r", "").Replace("\n", "\n ")
+ "\n</Canvas>";

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

@ -1,17 +1,18 @@ @@ -1,17 +1,18 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Text;
using System.IO;
using System.Xml;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using NUnit.Framework;
using ICSharpCode.WpfDesign.Designer;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.Designer.Services;
using System;
using System.Text;
using System.IO;
using System.Xml;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using NUnit.Framework;
using ICSharpCode.WpfDesign.Designer;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.Designer.Services;
namespace ICSharpCode.WpfDesign.Tests.Designer
{
@ -235,5 +236,52 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -235,5 +236,52 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
"</Canvas>", canvas.Context);
AssertLog("");
}
[Test]
public void AddMultiBindingToTextBox()
{
DesignItem button = CreateCanvasContext("<Button/>");
DesignItem canvas = button.Parent;
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
canvas.Properties["Children"].CollectionElements.Add(textBox);
textBox.Properties[TextBox.TextProperty].SetValue(new MultiBinding());
DesignItem multiBindingItem = textBox.Properties[TextBox.TextProperty].Value;
multiBindingItem.Properties["Converter"].SetValue(new MyMultiConverter());
DesignItemProperty bindingsProp = multiBindingItem.ContentProperty;
Assert.IsTrue(bindingsProp.IsCollection);
Assert.AreEqual(bindingsProp.Name, "Bindings");
DesignItem bindingItem = canvas.Services.Component.RegisterComponentForDesigner(new Binding());
bindingItem.Properties["Path"].SetValue("SomeProperty");
bindingsProp.CollectionElements.Add(bindingItem);
string expectedXaml = "<Button />\n" +
"<TextBox>\n" +
" <MultiBinding>\n" +
" <MultiBinding.Converter>\n" +
" <t:MyMultiConverter />\n" +
" </MultiBinding.Converter>\n" +
" <Binding Path=\"SomeProperty\" />\n" +
" </MultiBinding>\n" +
"</TextBox>";
AssertCanvasDesignerOutput(expectedXaml, button.Context);
AssertLog("");
}
}
public class MyMultiConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
return new object[targetTypes.Length];
}
}
}

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

@ -18,6 +18,11 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -18,6 +18,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// </summary>
public static bool CanPrint(XamlObject obj)
{
if (obj.ElementType == typeof(System.Windows.Data.MultiBinding) ||
obj.ElementType == typeof(System.Windows.Data.PriorityBinding)) {
return false;
}
return true;
}

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

@ -175,7 +175,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -175,7 +175,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
void UpdateMarkupExtensionChain()
{
var obj = this;
while (obj != null && obj.IsMarkupExtension) {
while (obj != null && obj.IsMarkupExtension && obj.ParentProperty != null) {
obj.ParentProperty.UpdateValueOnInstance();
obj = obj.ParentObject;
}
@ -345,7 +345,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -345,7 +345,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
void CreateWrapper()
{
if (Instance is Binding) {
if (Instance is BindingBase) {
wrapper = new BindingWrapper();
} else if (Instance is StaticResourceExtension) {
wrapper = new StaticResourceWrapper();

Loading…
Cancel
Save