Пример #1
0
		public void BindRectangle ()
		{
			Data data = new Data ();
			data.InnerData = new Data { Opacity = 1.0f };

			Rectangle rectangle = new Rectangle { Opacity = 0f };
			rectangle.DataContext = data;

			Binding binding = new Binding ("InnerData.Opacity");
			rectangle.SetBinding (Shape.OpacityProperty, binding);
			Assert.AreEqual (data.InnerData.Opacity, rectangle.Opacity, "#1");

			binding = new Binding ("Opacity");
			rectangle.SetBinding (Shape.OpacityProperty, binding);
			Assert.AreEqual (data.Opacity, rectangle.Opacity, "#2");
		}
Пример #2
0
		public void ChangeSourceValue()
		{
			Data data = new Data { Opacity = 0.5 };
			Rectangle r = new Rectangle();
			r.SetBinding(Rectangle.OpacityProperty, new Binding { Path = new PropertyPath("Opacity"), Source = data });
			Assert.AreEqual(data.Opacity, r.Opacity, "#1");
			data.Opacity = 0;
			Assert.AreNotEqual(data.Opacity, r.Opacity, "#2");
		}
Пример #3
0
		public void TestOneWayBinding ()
		{
			Data data = new Data ();
			Rectangle rectangle = new Rectangle { Opacity = 0f };
			Binding binding = new Binding {
				Path = new PropertyPath("Opacity"),
				Mode = BindingMode.OneWay,
				Source = data
			};

			rectangle.SetBinding (Rectangle.OpacityProperty, binding);
			Assert.AreEqual (data.Opacity, rectangle.Opacity);
			data.Opacity = 0.0f;
			Assert.AreNotEqual (data.Opacity, rectangle.Opacity, string.Format ("{0}-{1}", data.Opacity, rectangle.Opacity));
		}
Пример #4
0
		public void ChangeAfterBinding ()
		{
			Data data = new Data ();
			Binding binding = new Binding {
				Path = new PropertyPath ("Opacity"),
				Source = data,
				Mode = BindingMode.OneWay
			};

			Rectangle r = new Rectangle { Opacity = 0.0 };
			r.SetBinding (Shape.OpacityProperty, binding);
			Assert.AreEqual (data.Opacity, r.Opacity);
			r.Opacity = 1.0;
			Assert.AreEqual (1.0, r.Opacity);
			data.Opacity = 0.0f;
			Assert.AreEqual (1.0, r.Opacity);
		}
Пример #5
0
        public void TestTwoWayBinding10 ()
        {
            ValidationErrorEventArgs bindingEx = null;
            Data data = new Data();

            Rectangle r = new Rectangle();
            r.BindingValidationError += delegate(object o, ValidationErrorEventArgs e)
            {
                bindingEx = e;
            };
            r.SetBinding(Rectangle.IsHitTestVisibleProperty, new Binding
            {
                Path = new PropertyPath("ThrowExceptionsOnUpdate"),
                Source = data,
                Mode = BindingMode.TwoWay,
                NotifyOnValidationError = true,
                ValidatesOnExceptions = true
            });
            Assert.IsFalse(r.IsHitTestVisible, "#1");
            r.IsHitTestVisible = true;
            Assert.IsTrue(r.IsHitTestVisible, "#2");
            Assert.IsNotNull(bindingEx, "#3");
        }
Пример #6
0
		public void TestOnceOffBinding ()
		{
			Data data = new Data ();
			Rectangle rectangle = new Rectangle { Opacity = 0f };
			Binding binding = new Binding {
					Path = new PropertyPath("Opacity"), 
					Mode = BindingMode.OneTime, 
					Source = data
			};

			rectangle.SetBinding (Rectangle.OpacityProperty, binding);
			Assert.AreEqual (data.Opacity, rectangle.Opacity, "#1");
			Assert.IsTrue(rectangle.ReadLocalValue(Rectangle.OpacityProperty) is BindingExpressionBase, "#2");
			data.Opacity = 0;
			Assert.AreNotEqual (data.Opacity, rectangle.Opacity, "#3");
		}
Пример #7
0
		public void IndexerOnObservableIndexableProperty_TwoWay ()
		{
			var data = new Data { };
			for (double i = 0; i < 5; i++)
				data.ObservableDoubles.Add (i);

			var rect = new Rectangle { DataContext = data };
			rect.SetBinding (Rectangle.WidthProperty, new Binding {
				Mode = BindingMode.TwoWay,
				Path = new PropertyPath ("ObservableDoubles[2]"),
			});

			Assert.AreEqual (2, rect.Width, "#1");

			data.ObservableDoubles [2] = 30.0;
			Assert.AreEqual (30, rect.Width, "#2");
		}
Пример #8
0
		public void TestTwoWayBinding()
		{
			Data data = new Data { Opacity = 0.5 };
			Rectangle r = new Rectangle();
			r.SetBinding(Rectangle.OpacityProperty, new Binding { Path = new PropertyPath("Opacity"),
						Source = data,
						Mode = BindingMode.TwoWay });
			Assert.AreEqual(0.5, r.Opacity, "#1");
			Assert.AreEqual(0.5, data.Opacity, "#2");
			data.Opacity = 0;
			Assert.AreEqual(0.5, r.Opacity, "#3");
			r.Opacity = 1;
			Assert.IsTrue (r.ReadLocalValue (Rectangle.OpacityProperty) is BindingExpressionBase, "#4");
			Assert.AreEqual(1, r.Opacity, "#5");
			Assert.AreEqual(1, data.Opacity, "#6");

			r.ClearValue(Rectangle.OpacityProperty);
			r.Opacity = 0.5;
			Assert.AreEqual(1, data.Opacity, "#7");
		}
Пример #9
0
		public void IndexerOnIndexableProperty_TwoWay ()
		{
			var data = new Data { };
			data.DoubleList.AddRange (new double [] { 0, 1, 2, 3, 4 });

			var rect = new Rectangle { DataContext = data };
			rect.SetBinding (Rectangle.WidthProperty, new Binding {
				Mode = BindingMode.TwoWay,
				Path = new PropertyPath ("DoubleList[2]"),
			});

			Assert.AreEqual (2, rect.Width, "#1");

			rect.Width = 6;
			Assert.AreEqual (6, data.DoubleList[2], "#2");
		}
Пример #10
0
		public void IndexerOnIndexableProperty_IndexTooLarge_INCC ()
		{
			// Attach the binding, then add values to the collection to
			// force an update through the INotifyCollectionChanged interface
			var data = new Data { };
			var rect = new Rectangle { DataContext = data };
			rect.SetBinding (Rectangle.WidthProperty, new Binding ("ObservableDoubles[1]"));

			Assert.IsTrue (double.IsNaN (rect.Width), "#1");
			data.ObservableDoubles.Add (1.0);
			data.ObservableDoubles.Add (2.0);
			Assert.AreEqual (2.0, rect.Width, "#2");
		}
Пример #11
0
		public void IndexerOnIndexableProperty_IndexTooLarge ()
		{
			var data = new Data { };
			data.DoubleList.AddRange (new double [] { 0, 1, 2, 3, 4 });

			var rect = new Rectangle { DataContext = data };
			rect.SetBinding (Rectangle.WidthProperty, new Binding ("DoubleList[20]"));

			Assert.IsTrue(double.IsNaN (rect.Width), "#1");
		}
Пример #12
0
		public void IndexerOnIndexableProperty_OneWay ()
		{
			var data = new Data { };
			data.DoubleList.AddRange (new double [] { 0, 1, 2, 3, 4 });

			var rect = new Rectangle { DataContext = data };
			rect.SetBinding (Rectangle.WidthProperty, new Binding ("DoubleList[2]"));

			Assert.AreEqual (2, rect.Width, "#1");
		}
Пример #13
0
		public void IncompletePath ()
		{
			Data data = new Data { Brush = null };
			Rectangle r = new Rectangle {
				DataContext = data
			};
			r.SetBinding (Rectangle.WidthProperty, new Binding ("Brush.Color.A"));
			Assert.IsTrue (double.IsNaN (r.Width), "#1");

			data.Brush = new SolidColorBrush (Colors.Black);
			Assert.IsTrue (double.IsNaN (r.Width), "#2");

			r.SetBinding (Rectangle.WidthProperty, new Binding ("Brush.Color.A"));
			Assert.AreEqual (255, r.Width, "#2");
		}