2 using System
.ComponentModel
;
3 using System
.Globalization
;
6 using System
.Windows
.Controls
;
7 using System
.Windows
.Controls
.Primitives
;
8 using System
.Windows
.Documents
;
9 using System
.Windows
.Ink
;
10 using System
.Windows
.Input
;
11 using System
.Windows
.Markup
;
12 using System
.Windows
.Media
;
13 using System
.Windows
.Media
.Animation
;
14 using System
.Windows
.Shapes
;
15 using System
.Collections
.Generic
;
16 using Mono
.Moonlight
.UnitTesting
;
17 using Microsoft
.VisualStudio
.TestTools
.UnitTesting
;
19 namespace MoonTest
.System
.Windows
22 public class StyleTest4_TypeConverterOnProperty_MisnamedProperty
{
24 public class HappyStructConverter
: TypeConverter
{
25 public override bool CanConvertFrom (ITypeDescriptorContext context
, Type sourceType
)
27 return sourceType
== typeof(string);
30 public override object ConvertFrom (ITypeDescriptorContext context
, CultureInfo culture
, object value)
32 // don't actually parse the string, just return a new HappyStruct
33 return new HappyStruct (5, 5);
37 public struct HappyStruct
{
38 public HappyStruct (int _x
, int _y
)
54 public override string ToString ()
56 return string.Format ("Happy ({0},{1})", x
, y
);
63 public class HappyButton
: Button
{
64 public static readonly DependencyProperty HappyProperty
= DependencyProperty
.Register ("Happpy", typeof (HappyStruct
),
68 [TypeConverter (typeof (HappyStructConverter
))]
69 public HappyStruct Happy
{
70 get { return (HappyStruct)GetValue (HappyButton.HappyProperty); }
71 set { SetValue (HappyButton.HappyProperty, value); }
76 public void TestWithValue ()
78 HappyButton b
= new HappyButton ();
79 Style s
= new Style (typeof (HappyButton
));
81 s
.Setters
.Add (new Setter (HappyButton
.HappyProperty
, new HappyStruct (10, 10)));
85 Assert
.AreEqual (new HappyStruct (10, 10), b
.Happy
);
90 public void TestWithString ()
92 HappyButton b
= new HappyButton ();
93 Style s
= new Style (typeof (HappyButton
));
95 s
.Setters
.Add (new Setter (HappyButton
.HappyProperty
, "just to invoke the type converter"));
97 Assert
.Throws
<XamlParseException
> (delegate {