public void Check_Default ()
	{
		DependencyProperty property = DependencyProperty.Register ("MyProp", typeof (int), typeof(Rectangle), new PropertyMetadata (100));
		Rectangle r = new Rectangle ();
		r.SetValue (property, 10);
		Assert.AreEqual (10, r.GetValue (property), "#1");
		r.ClearValue (property);
		Assert.AreEqual (100, r.GetValue (property), "#2");
	}
	public void Check_Default_Nullable ()
	{
		DependencyProperty property = DependencyProperty.Register ("MyPropNullable", typeof (int?), typeof(Rectangle), null);
		Rectangle r = new Rectangle ();
		r.SetValue (property, 10);
		Assert.AreEqual (10, r.GetValue (property), "#1");
		r.ClearValue (property);
		Assert.AreEqual (null, r.GetValue (property), "#2");
	}
Example #3
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 #4
0
		public void DataContext_ClearLocal ()
		{
			Binding b = new Binding("");

			Canvas c = new Canvas();
			c.DataContext = new SolidColorBrush(Colors.Blue);

			Rectangle r = new Rectangle();
			r.DataContext = new SolidColorBrush(Colors.Green);

			c.Children.Add(r);
			r.SetBinding(Rectangle.FillProperty, b);

			// clearing the value allows the inherited
			// DataContext to be used again (and causes
			// the bound property to be updated)
			r.ClearValue (FrameworkElement.DataContextProperty);
			Assert.AreEqual(c.DataContext, r.DataContext, "#1");
			Assert.AreEqual(c.DataContext, r.Fill, "#2");
		}
Example #5
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 #6
0
		public void NullOldValue ()
		{
			Rectangle r = new Rectangle ();

			Style style = new Style (typeof (Rectangle));
			style.Setters.Add (new Setter (FrameworkElement.WidthProperty, 100));
			style.Setters.Add (new Setter (FrameworkElement.HeightProperty, "CRASH ME"));
			r.Style = style;
			r.Height = 2;
			r.ClearValue (Rectangle.HeightProperty);
			r.Height = 2;
			r.ClearValue (Rectangle.HeightProperty);
		}