Ejemplo n.º 1
0
		public void BindDataContext ()
		{
			// Bind the DataContext of the FE to its DataContext
			TextBlock block = new TextBlock ();
			block.SetBinding (TextBlock.DataContextProperty, new Binding ());
			CreateAsyncTest (block,
				() => Assert.IsNull (block.DataContext, "#1"),
				() => TestPanel.DataContext = "Hello",
				() => {
					Assert.AreEqual ("Hello", block.DataContext, "#2");
					Assert.IsInstanceOfType<BindingExpressionBase> (block.ReadLocalValue (TextBlock.DataContextProperty), "#3");
				}
			);
		}
Ejemplo n.º 2
0
		public void PromotingDefaultValue ()
		{
			TextBlock tb = new TextBlock ();
			tb.Text = "Hi there";

			Storyboard sb = new Storyboard { Duration = new Duration (TimeSpan.FromMilliseconds(500)) };
			ColorAnimation anim = new ColorAnimation { To = Colors.Blue, Duration = new Duration (TimeSpan.FromSeconds(0)) };
			Storyboard.SetTarget (anim, tb);
			Storyboard.SetTargetProperty (anim, new PropertyPath ("(TextBlock.Foreground).(SolidColorBrush.Color)"));

			sb.Children.Add (anim);

			Assert.AreEqual (DependencyProperty.UnsetValue, tb.ReadLocalValue (TextBlock.ForegroundProperty), "#0");

			bool completed = false;

			sb.Completed += (o,e) => completed = true;

			sb.Begin ();

			// beginning the storyboard promotes default values to local values.

			Assert.AreNotEqual (DependencyProperty.UnsetValue, tb.ReadLocalValue (TextBlock.ForegroundProperty), "#1");

			// but the value is identical to the default value (i.e. SolidColorBrush ("Black"))

			Assert.AreEqual (Colors.Black, ((SolidColorBrush)tb.ReadLocalValue (TextBlock.ForegroundProperty)).Color, "#2");
			
			EnqueueConditional (() => completed);
			Enqueue (() => { Console.WriteLine ("testing animated value"); Assert.AreEqual (Colors.Blue, ((SolidColorBrush)tb.ReadLocalValue (TextBlock.ForegroundProperty)).Color, "#3"); });
			EnqueueTestComplete ();
		}