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

Commit ee33a1c

Browse files
author
gumme
committed
Added tests for testing that property values are written correctly as attribute in XAML; namespace prefix should only be used for attached properties, and prefix should be generated and added if not already present.
1 parent 07c44c9 commit ee33a1c

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
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
using System;
4+
using System.Windows;
45
using System.Windows.Controls;
6+
57
using NUnit.Framework;
68

79
namespace ICSharpCode.WpfDesign.Tests.Designer
@@ -105,6 +107,18 @@ public void AddMultipleControls()
105107

106108
public class CustomButton : Button
107109
{
110+
public static readonly DependencyProperty TestAttachedProperty = DependencyProperty.RegisterAttached("TestAttached", typeof(double), typeof(CustomButton),
111+
new FrameworkPropertyMetadata(Double.NaN));
112+
113+
public static double GetTestAttached(UIElement element)
114+
{
115+
return (double)element.GetValue(TestAttachedProperty);
116+
}
117+
118+
public static void SetTestAttached(UIElement element, double value)
119+
{
120+
element.SetValue(TestAttachedProperty, value);
121+
}
108122
}
109123

110124
public class CustomCheckBox : CheckBox
@@ -116,6 +130,18 @@ namespace ICSharpCode.WpfDesign.Tests.Controls
116130
{
117131
public class CustomButton : Button
118132
{
133+
public static readonly DependencyProperty TestAttachedProperty = DependencyProperty.RegisterAttached("TestAttached", typeof(double), typeof(CustomButton),
134+
new FrameworkPropertyMetadata(Double.NaN));
135+
136+
public static double GetTestAttached(UIElement element)
137+
{
138+
return (double)element.GetValue(TestAttachedProperty);
139+
}
140+
141+
public static void SetTestAttached(UIElement element, double value)
142+
{
143+
element.SetValue(TestAttachedProperty, value);
144+
}
119145
}
120146

121147
public class CustomCheckBox : CheckBox
@@ -127,6 +153,18 @@ namespace ICSharpCode.WpfDesign.Tests.OtherControls
127153
{
128154
public class CustomButton : Button
129155
{
156+
public static readonly DependencyProperty TestAttachedProperty = DependencyProperty.RegisterAttached("TestAttached", typeof(double), typeof(CustomButton),
157+
new FrameworkPropertyMetadata(Double.NaN));
158+
159+
public static double GetTestAttached(UIElement element)
160+
{
161+
return (double)element.GetValue(TestAttachedProperty);
162+
}
163+
164+
public static void SetTestAttached(UIElement element, double value)
165+
{
166+
element.SetValue(TestAttachedProperty, value);
167+
}
130168
}
131169

132170
public class CustomCheckBox : CheckBox

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Windows;
6+
using System.Windows.Controls;
67
using System.Windows.Data;
78
using System.Windows.Markup;
89

@@ -47,5 +48,29 @@ public void SetContentToString()
4748
button.Properties.GetProperty("Content").SetValue("Hello World!");
4849
AssertCanvasDesignerOutput("<Button Width=\"100\" Height=\"200\" Content=\"Hello World!\" />", button.Context);
4950
}
51+
52+
[Test]
53+
public void SetAttachedProperties()
54+
{
55+
DesignItem button = CreateCanvasContext("<Button />");
56+
57+
button.Properties.GetAttachedProperty(Grid.ColumnProperty).SetValue(0);
58+
button.Properties.GetAttachedProperty(CustomButton.TestAttachedProperty).SetValue(0);
59+
button.Properties.GetAttachedProperty(ICSharpCode.WpfDesign.Tests.Controls.CustomButton.TestAttachedProperty).SetValue(0);
60+
button.Properties.GetAttachedProperty(ICSharpCode.WpfDesign.Tests.OtherControls.CustomButton.TestAttachedProperty).SetValue(0);
61+
62+
AssertCanvasDesignerOutput("<Button Grid.Column=\"0\" t:CustomButton.TestAttached=\"0\" sdtcontrols:CustomButton.TestAttached=\"0\" Controls0:CustomButton.TestAttached=\"0\" />",
63+
button.Context,
64+
"xmlns:sdtcontrols=\"http://sharpdevelop.net/WpfDesign/Tests/Controls\"",
65+
"xmlns:Controls0=\"clr-namespace:ICSharpCode.WpfDesign.Tests.OtherControls;assembly=ICSharpCode.WpfDesign.Tests\"");
66+
}
67+
68+
[Test]
69+
public void SetInstanceProperty()
70+
{
71+
DesignItem button = CreateCanvasContext("<Button />");
72+
button.Properties.GetProperty("Width").SetValue(10);
73+
AssertCanvasDesignerOutput("<Button Width=\"10\" />", button.Context);
74+
}
5075
}
5176
}

0 commit comments

Comments
 (0)