Example #1
0
	public void ReadLocalProperty ()
	{
		PropertyUpdater data = new PropertyUpdater ();
		Rectangle rectangle = new Rectangle { Opacity = 0f };
		Binding binding = new Binding {
			Path = new PropertyPath ("Opacity"),
			Mode = BindingMode.OneWay,
			Source = data
		};
		Assert.AreEqual (0.0, (double) rectangle.ReadLocalValue (Rectangle.OpacityProperty), "#1");
		
		rectangle.SetBinding (Rectangle.OpacityProperty, binding);
		
		Assert.IsTrue(rectangle.ReadLocalValue (Rectangle.OpacityProperty) is BindingExpressionBase, "#2");
	}
Example #2
0
		public void BasicBind ()
		{
			Rectangle rectangle = new Rectangle ();
			Binding binding = new Binding ("Opacity");
			binding.Source = new Data { Opacity = 0.0 };

			rectangle.SetBinding (Rectangle.OpacityProperty, binding);
			
			Assert.AreEqual (0.0, rectangle.Opacity, "#1");
			Assert.IsTrue (rectangle.ReadLocalValue (Rectangle.OpacityProperty) is BindingExpressionBase, "#2");
			rectangle.Opacity = 1.0;
			Assert.AreEqual(1.0, rectangle.Opacity, "#3");
			Assert.AreEqual (1.0, rectangle.ReadLocalValue (Rectangle.OpacityProperty), "#4");
			rectangle.SetBinding (Rectangle.OpacityProperty, binding);
			Assert.IsTrue (rectangle.ReadLocalValue (Rectangle.OpacityProperty) is BindingExpressionBase, "#5");
			Assert.AreEqual (0.0, rectangle.Opacity, "#6");
			rectangle.ClearValue (Rectangle.OpacityProperty);
			Assert.AreEqual (1.0, rectangle.Opacity, "#7");
			
			Assert.AreEqual (DependencyProperty.UnsetValue, rectangle.ReadLocalValue (Rectangle.OpacityProperty), "#8");
		}
Example #3
0
	public void TestOnceOffBinding2 ()
	{
		Canvas c = new Canvas { DataContext = 5.0 };
		Rectangle r = new Rectangle ();
		r.SetBinding (Rectangle.HeightProperty, new Binding { Mode = BindingMode.OneTime });
		Assert.IsInstanceOfType<BindingExpressionBase> (r.ReadLocalValue (Rectangle.HeightProperty), "#1");
		c.Children.Add (r);
		Assert.IsInstanceOfType<BindingExpressionBase> (r.ReadLocalValue (Rectangle.HeightProperty), "#2");
		CreateAsyncTest (c,
			() => c.DataContext = 6.0,
			() => {
				Assert.IsInstanceOfType<BindingExpressionBase> (r.ReadLocalValue (Rectangle.HeightProperty), "#3");
				Assert.AreEqual (6.0, r.Height, "#2");
			}
		);
	}
Example #4
0
		public void TestOnceOffBinding3()
		{
			var source = new Rectangle { Width = 100 };
			var dest = new Rectangle();

			dest.SetBinding(Rectangle.WidthProperty, new Binding("Width") {
				Mode = BindingMode.OneTime,
				Source = source,
			});

			Assert.AreEqual(100, dest.Width, "#1");
			Assert.IsInstanceOfType<BindingExpressionBase>(dest.ReadLocalValue(Rectangle.WidthProperty), "#a");
			source.Width = 200;
			Assert.AreEqual(100, dest.Width, "#2");
			Assert.IsInstanceOfType<BindingExpressionBase>(dest.ReadLocalValue(Rectangle.WidthProperty), "#b");
		}
Example #5
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");
		}
Example #6
0
		public void TestTwoWayBinding2()
		{
			PropertyUpdater data = new PropertyUpdater { Opacity = 0.5f };
			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.0, 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");
		}
Example #7
0
		public void RestoreOriginalValueOnStop_LocalValue()
		{
			bool completed = false;
			var target = new Rectangle { Opacity = 0.5 };
			Storyboard sb = new Storyboard { FillBehavior = FillBehavior.Stop };
			DoubleAnimation anim = new DoubleAnimation { From = 0, To = 1, Duration = TimeSpan.Zero };
			Storyboard.SetTarget(anim, target);
			Storyboard.SetTargetProperty(anim, new PropertyPath("Opacity"));
			sb.Children.Add(anim);
			sb.Completed += (o, e) => completed = true;
			sb.Begin();

			EnqueueConditional(() => completed, "#1");
			Enqueue(() => Assert.AreEqual(0.5, (double)target.ReadLocalValue(FrameworkElement.OpacityProperty), "#2"));
			EnqueueTestComplete();
		}
Example #8
0
		public void DataContextTest ()
		{
			object context = new object ();
			Grid grid = new Grid { DataContext = context };
			Rectangle r = new Rectangle ();
			grid.Children.Add (r);

			Assert.AreEqual (context, r.DataContext, "#1");
			Assert.AreEqual (DependencyProperty.UnsetValue, r.ReadLocalValue (FrameworkElement.DataContextProperty), "#2");
		}
Example #9
0
		public void ArrangeTest_ChildLargerThanFinalRect_LocalValue ()
		{
			Border c = new Border ();
			Rectangle r = new Rectangle ();

			c.Child = r;

			r.Width = 50;
			r.Height = 50;

			c.Measure (new Size (25, 25));
			c.Arrange (new Rect (0, 0, 25, 25));

			Assert.AreEqual (DependencyProperty.UnsetValue, r.ReadLocalValue (FrameworkElement.ActualWidthProperty), "local r.actualwidth");
			Assert.AreEqual (DependencyProperty.UnsetValue, c.ReadLocalValue (FrameworkElement.ActualWidthProperty), "local c.actualwidth");

		}