Exemple #1
0
		public void BindContentPresenterContent ()
		{
			ContentPresenter presenter = new ContentPresenter ();
			presenter.SetBinding (ContentPresenter.ContentProperty, new Binding ("Opacity"));

			CustomControl c = new CustomControl { Content = presenter };
			CreateAsyncTest (c,
				() => {
					c.DataContext = new Data { Opacity = 1.0 };
				}, () => {
					Assert.AreEqual (1.0, presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#1");
					Assert.AreEqual (1.0, presenter.Content, "#2");

					c.DataContext = new Data { Opacity = 0.0 };
				}, () => {
					Assert.AreEqual (0.0, presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#3");
					Assert.AreEqual (0.0, presenter.Content, "#4");
				}
			);
		}
Exemple #2
0
		public void DataContextTest7 ()
		{
			// A null content is copied to the datacontext too.
			ContentPresenter presenter = new ContentPresenter ();
			CreateAsyncTest (presenter,
				() => {
					presenter.Content = new object ();
				}, () => {
					Assert.AreEqual (presenter.Content, presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#1");
					presenter.Content = null;
				}, () => {
					Assert.AreEqual (null, presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#2");

				}
			);
		}
Exemple #3
0
		public void DataContextTest5b ()
		{
			// When the ContentPresenter is in the tree, its DataContext gets set to ContentPresenter.Content
			// when it is loaded
			object o = new object ();
			object content = new object ();
			ContentPresenter c = new ContentPresenter { Content = content };
			CreateAsyncTest (c,
				() => {
					Assert.AreEqual (content, c.DataContext, "#1");
					Assert.AreEqual (content, c.ReadLocalValue (FrameworkElement.DataContextProperty), "#2");
				}
			);
		}
Exemple #4
0
		public void DataContextTest5 ()
		{
			// When the ContentPresenter is in the tree, its DataContext gets set to ContentPresenter.Content
			// when it is loaded
			object o = new object ();
			ContentPresenter c = new ContentPresenter { DataContext = o };
			Assert.AreEqual (o, c.DataContext, "#1");
			CreateAsyncTest (c,
				() => {
					Assert.IsNull (c.DataContext, "#2");
					Assert.IsNull (c.ReadLocalValue (ContentPresenter.DataContextProperty), "#2b");
				},
				() => {
					c.DataContext = o;
					Assert.AreEqual (o, c.DataContext, "#3");
					Assert.AreEqual (o, c.ReadLocalValue (ContentPresenter.DataContextProperty), "#3b");
				},
				() => Assert.AreEqual (o, c.DataContext, "#4")
			);
		}
Exemple #5
0
		public void DataContextTest2 ()
		{
			// Changing the content updates the datacontext
			ContentPresenter c = new ContentPresenter ();
			c.Content = new object ();
			CreateAsyncTest (c,
				() => {
					Assert.AreEqual (c.Content, c.DataContext, "#1");
					Assert.AreEqual (c.Content, c.ReadLocalValue (ContentPresenter.DataContextProperty), "#1b");
					c.Content = new object ();
				},
				() => {
					Assert.AreEqual (c.Content, c.DataContext, "#2");
					Assert.AreEqual (c.Content, c.ReadLocalValue (ContentPresenter.DataContextProperty), "#2b");
				}
			);
		}
Exemple #6
0
		public void DataContextTest_DataContextUpdatesAsync ()
		{
			var presenter = new ContentPresenter ();
			presenter.SetBinding (ContentPresenter.DataContextProperty, new Binding ());
			Assert.IsInstanceOfType<BindingExpression> (presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#1");

			presenter.Content = new object ();
			Assert.IsInstanceOfType<BindingExpression> (presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#2");

			TestPanel.Children.Add (presenter);
			Assert.IsInstanceOfType<BindingExpression> (presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#3");

			Enqueue (() => {
				Assert.AreSame (presenter.Content, presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#4");
			});
			EnqueueTestComplete ();
		}