コード例 #1
0
ファイル: IValueConverterTest.cs プロジェクト: ynkbt/moon
        public void InvalidValueConverter2()
        {
            BoundData data             = new BoundData {
            };
            InvalidConverter converter = new InvalidConverter {
                Value = 50
            };
            TextBlock block = new TextBlock {
                Visibility = Visibility.Collapsed
            };

            block.SetBinding(TextBlock.VisibilityProperty, new Binding {
                Mode      = BindingMode.TwoWay,
                Path      = new PropertyPath("Converting"),
                Source    = data,
                Converter = converter
            });

            Assert.AreEqual(Visibility.Visible, block.Visibility, "#0");

            // Make TextBlock.Visibility update
            data.Converting = 5;
            Assert.AreEqual(Visibility.Visible, block.Visibility, "#1");

            converter.Value = 1;
            data.Converting = 6;
            Assert.AreEqual(Visibility.Visible, block.Visibility, "#2");

            converter.Value = Visibility.Collapsed;
            data.Converting = 7;
            Assert.AreEqual(Visibility.Collapsed, block.Visibility, "#3");
        }
コード例 #2
0
ファイル: IValueConverterTest.cs プロジェクト: ynkbt/moon
        public void InvalidValueConverter3()
        {
            BoundData data = new BoundData {
                Visibility = Visibility.Collapsed
            };
            InvalidConverter converter = new InvalidConverter {
                Value = 0
            };
            TextBlock block = new TextBlock {
            };

            block.SetBinding(TextBlock.TextProperty, new Binding {
                Mode      = BindingMode.TwoWay,
                Path      = new PropertyPath("Visibility"),
                Source    = data,
                Converter = converter
            });


            Assert.AreEqual(Visibility.Collapsed, data.Visibility, "#1");

            block.Text = "a";
            Assert.AreEqual(Visibility.Collapsed, data.Visibility, "#2");

            converter.Value = Visibility.Visible;
            block.Text      = "b";
            Assert.AreEqual(Visibility.Visible, data.Visibility, "#3");

            converter.Value = "Collapsed";
            block.Text      = "c";

            Assert.AreEqual(Visibility.Collapsed, data.Visibility, "#4");
        }
コード例 #3
0
ファイル: IValueConverterTest.cs プロジェクト: ynkbt/moon
        public void InvalidValueConverter()
        {
            BoundData data             = new BoundData {
            };
            InvalidConverter converter = new InvalidConverter {
                Value = 123
            };
            TextBlock block = new TextBlock();

            block.SetBinding(TextBlock.TextProperty, new Binding {
                Mode      = BindingMode.TwoWay,
                Path      = new PropertyPath("Converting"),
                Source    = data,
                Converter = converter
            });

            // Make TextBlock.Text update
            data.Converting = 5;
            Assert.AreEqual("123", block.Text, "#1");

            // Make data.Converting update
            block.Text = "Update";
            Assert.AreEqual(123, data.Converting, "#2");

            // What happens if we return something crazy
            converter.Value = "I'm a string";

            // Make TextBlock.Text update
            data.Converting = 5;
            Assert.AreEqual("I'm a string", block.Text, "#1");

            // Make data.Converting update
            block.Text = "Hello";
            Assert.AreEqual(5, data.Converting, "#2");
        }
コード例 #4
0
ファイル: IValueConverterTest.cs プロジェクト: ynkbt/moon
        public void Setup()
        {
            //FIXME: Use a test where you bind a Brush property to a Rectangle - it fails!
            data = new BoundData();
            rect = new Rectangle {
                Opacity = 0.4
            };
            Binding binding = new Binding {
                Path = new PropertyPath("Color"), Source = data, Mode = BindingMode.TwoWay
            };

            binding.Converter = new SolidBrushConverter();
            rect.SetBinding(Rectangle.FillProperty, binding);
        }
コード例 #5
0
ファイル: IValueConverterTest.cs プロジェクト: ynkbt/moon
        public void InvalidValueConverter5()
        {
            BoundData data = new BoundData {
                GridLength = new GridLength(0, GridUnitType.Auto)
            };
            TextBlock block = new TextBlock {
            };

            block.SetBinding(TextBlock.TextProperty, new Binding {
                Mode   = BindingMode.TwoWay,
                Path   = new PropertyPath("GridLength"),
                Source = data
            });

            // Check if we use the same type conversions as for Style and Storyboards
            Assert.IsTrue(data.GridLength.IsAuto, "#1");

            block.Text = "a";
            Assert.IsTrue(data.GridLength.IsAuto, "#2");
        }
コード例 #6
0
ファイル: IValueConverterTest.cs プロジェクト: kangaroo/moon
		public void InvalidValueConverter5 ()
		{
			BoundData data = new BoundData { GridLength = new GridLength (0, GridUnitType.Auto) };
			TextBlock block = new TextBlock { };

			block.SetBinding (TextBlock.TextProperty, new Binding {
				Mode = BindingMode.TwoWay,
				Path = new PropertyPath ("GridLength"),
				Source = data
			});

			// Check if we use the same type conversions as for Style and Storyboards
			Assert.IsTrue (data.GridLength.IsAuto, "#1");

			block.Text = "a";
			Assert.IsTrue (data.GridLength.IsAuto, "#2");
								
		}
コード例 #7
0
ファイル: IValueConverterTest.cs プロジェクト: kangaroo/moon
		public void InvalidValueConverter3 ()
		{
			BoundData data = new BoundData { Visibility = Visibility.Collapsed };
			InvalidConverter converter = new InvalidConverter { Value = 0 };
			TextBlock block = new TextBlock { };
			block.SetBinding (TextBlock.TextProperty, new Binding {
				Mode = BindingMode.TwoWay,
				Path = new PropertyPath ("Visibility"),
				Source = data,
				Converter = converter
			});

						
			Assert.AreEqual (Visibility.Collapsed, data.Visibility, "#1");

			block.Text = "a";
			Assert.AreEqual (Visibility.Collapsed, data.Visibility, "#2");

			converter.Value = Visibility.Visible;
			block.Text = "b";
			Assert.AreEqual (Visibility.Visible, data.Visibility, "#3");

			converter.Value = "Collapsed";
			block.Text = "c";

			Assert.AreEqual (Visibility.Collapsed, data.Visibility, "#4");
		}
コード例 #8
0
ファイル: IValueConverterTest.cs プロジェクト: kangaroo/moon
		public void InvalidValueConverter2 ()
		{
			BoundData data = new BoundData { };
			InvalidConverter converter = new InvalidConverter { Value = 50 };
			TextBlock block = new TextBlock { Visibility = Visibility.Collapsed };

			block.SetBinding (TextBlock.VisibilityProperty, new Binding {
				Mode = BindingMode.TwoWay,
				Path = new PropertyPath ("Converting"),
				Source = data,
				Converter = converter
			});

			Assert.AreEqual (Visibility.Visible, block.Visibility, "#0");

			// Make TextBlock.Visibility update
			data.Converting = 5;
			Assert.AreEqual (Visibility.Visible, block.Visibility, "#1");

			converter.Value = 1;
			data.Converting = 6;
			Assert.AreEqual (Visibility.Visible, block.Visibility, "#2");

			converter.Value = Visibility.Collapsed;
			data.Converting = 7;
			Assert.AreEqual (Visibility.Collapsed, block.Visibility, "#3");
		}
コード例 #9
0
ファイル: IValueConverterTest.cs プロジェクト: kangaroo/moon
		public void InvalidValueConverter ()
		{
			BoundData data = new BoundData { };
			InvalidConverter converter = new InvalidConverter { Value = 123 };
			TextBlock block = new TextBlock ();
			block.SetBinding (TextBlock.TextProperty, new Binding {
				Mode = BindingMode.TwoWay,
				Path = new PropertyPath ("Converting"),
				Source = data,
				Converter = converter
			});
			
			// Make TextBlock.Text update
			data.Converting = 5;
			Assert.AreEqual ("123", block.Text, "#1");

			// Make data.Converting update
			block.Text = "Update";
			Assert.AreEqual (123, data.Converting, "#2");

			// What happens if we return something crazy
			converter.Value = "I'm a string";

			// Make TextBlock.Text update
			data.Converting = 5;
			Assert.AreEqual ("I'm a string", block.Text, "#1");

			// Make data.Converting update
			block.Text = "Hello";
			Assert.AreEqual (5, data.Converting, "#2");
		}
コード例 #10
0
ファイル: IValueConverterTest.cs プロジェクト: kangaroo/moon
		public void Setup()
		{
			//FIXME: Use a test where you bind a Brush property to a Rectangle - it fails!
			data = new BoundData();
			rect = new Rectangle { Opacity = 0.4 };
			Binding binding = new Binding { Path = new PropertyPath("Color"), Source = data, Mode = BindingMode.TwoWay};
			binding.Converter = new SolidBrushConverter();
			rect.SetBinding(Rectangle.FillProperty, binding);
		}