示例#1
0
        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
        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
        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
        public void InvalidValueConverter4()
        {
            BoundData data = new BoundData {
                GridLength = new GridLength(0, GridUnitType.Auto)
            };
            InvalidConverter converter = new InvalidConverter {
                Value = "*"
            };
            TextBlock block = new TextBlock {
            };

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

            // 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.IsStar, "#2");
        }
示例#5
0
		public void InvalidValueConverter4 ()
		{
			BoundData data = new BoundData { GridLength = new GridLength (0, GridUnitType.Auto) };
			InvalidConverter converter = new InvalidConverter { Value = "*" };
			TextBlock block = new TextBlock { };
			block.SetBinding (TextBlock.TextProperty, new Binding {
				Mode = BindingMode.TwoWay,
				Path = new PropertyPath ("GridLength"),
				Source = data,
				Converter = converter
			});

			// 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.IsStar, "#2");
		}
示例#6
0
		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");
		}
示例#7
0
		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");
		}
示例#8
0
		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");
		}