Merge branch 'loaded-branch'
[moon.git] / test / 2.0 / moon-unit / System.Windows / StyleTest4.cs
blobb268720a98b02f45b70c666c8dd08df34fc06a4d
1 using System;
2 using System.ComponentModel;
3 using System.Globalization;
4 using System.Net;
5 using System.Windows;
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
21 [TestClass]
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)
40 x = _x;
41 y = _y;
44 public int X {
45 get { return x; }
46 set { x = value; }
49 public int Y {
50 get { return y; }
51 set { y = value; }
54 public override string ToString ()
56 return string.Format ("Happy ({0},{1})", x, y);
59 private int x;
60 private int y;
63 public class HappyButton : Button {
64 public static readonly DependencyProperty HappyProperty = DependencyProperty.Register ("Happpy", typeof (HappyStruct),
65 typeof (HappyButton),
66 null);
68 [TypeConverter (typeof (HappyStructConverter))]
69 public HappyStruct Happy {
70 get { return (HappyStruct)GetValue (HappyButton.HappyProperty); }
71 set { SetValue (HappyButton.HappyProperty, value); }
75 [TestMethod]
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)));
83 b.Style = s;
85 Assert.AreEqual (new HappyStruct (10, 10), b.Happy);
88 [TestMethod]
89 [MoonlightBug]
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 {
98 b.Style = s;
99 });