Inheritance: INotifyPropertyChanged, ILinked
Exemplo n.º 1
0
		public void MultiPathINPC_Standard_ChangeMiddleLeaf ()
		{
			var a = new INPC { Value = 0 };
			var b = new INPC { Value = 1 };
			var c = new INPC { Value = 2 };
			var d = new INPC { Value = 3 };
			var newC = new INPC { Value = 4 };

			a.Next = b;
			b.Next = c;
			c.Next = d;

			Rectangle r = new Rectangle { DataContext = a };
			r.SetBinding (Rectangle.WidthProperty, new Binding ("Next.Next.Next.Value"));

			// Replace the middle subtree. We should disconnect our property path
			// listeners and property changed listeners from 'c' and 'd'

			b.Next = newC;
			c.Next = new INPC { Value = 100 };
			d.Value = 19;
			Assert.IsTrue (double.IsNaN (r.Width), "#1");

			// We should reattach to  'd' now
			newC.Next = d;
			Assert.AreEqual (19, r.Width, "#3");
		}
Exemplo n.º 2
0
		public void MultiPathINPC_PathContainsNonINPC ()
		{
			// If 'b' is not INPC in the link a.b.c.d and we change b.Next, does Silverlight
			// realised that 'c' and 'd' are no longer in the property path? Does it ever unhook
			// from their PropertyChanged event?
			var a = new INPC { Value = 0 };
			var b = new NonINPC { Value = 1 };
			var c = new INPC { Value = 2 };
			var d = new INPC { Value = 3 };

			a.Next = b;
			b.Next = c;
			c.Next = d;

			Rectangle r = new Rectangle { DataContext = a };
			r.SetBinding (Rectangle.WidthProperty, new Binding ("Next.Next.Next.Value"));

			// This issues no propertychanged events. SL should not notice that 'b' has changed
			b.Next = new NonINPC { Value = 10 };
			Assert.AreEqual (3, r.Width, "#1");

			// This will emit a PropertyChanged event which doesn't change the property path
			d.Value = 4;
			Assert.AreEqual (4, r.Width, "#2");

			// This will emit a PC event which does change the property path. SL only verifies
			// from 'c' onwards.
			c.Next = new INPC { Value = 20 };
			Assert.AreEqual (20, r.Width, "#3");
		}
Exemplo n.º 3
0
		public void MultiPathINPC_Standard_ChangeLastLeaf ()
		{
			var a = new INPC { Value = 0 };
			var b = new INPC { Value = 1 };
			var c = new INPC { Value = 2 };
			var d = new INPC { Value = 3 };
			var newD = new INPC { Value = 4 };

			a.Next = b;
			b.Next = c;
			c.Next = d;

			Rectangle r = new Rectangle { DataContext = a };
			r.SetBinding (Rectangle.WidthProperty, new Binding ("Next.Next.Next.Value"));
			Assert.AreEqual (3, r.Width, "#1");
			
			c.Next = newD;
			Assert.AreEqual (4, r.Width, "#2");

			d.Value = 10;
			Assert.AreEqual (4, r.Width, "#3");
		}
Exemplo n.º 4
0
		public void MultiPathINPC_Standard_ChangeEntireTree ()
		{
			var a = new INPC { Value = 0 };
			var b = new INPC { Value = 1 };
			var c = new INPC { Value = 2 };
			var d = new INPC { Value = 3 };

			a.Next = b;
			b.Next = c;
			c.Next = d;

			Rectangle r = new Rectangle { DataContext = a };
			r.SetBinding (Rectangle.WidthProperty, new Binding ("Next.Next.Next.Value"));

			r.DataContext = null;
			a = new INPC { Value = 10 };
			r.DataContext = a;
			a.Next = new INPC { Value = 20 };
			a.Next.Next = new INPC { Value = 30 };
			a.Next.Next.Next = new INPC { Value = 40 };

			Assert.AreEqual (40, r.Width, "#1");
		}
Exemplo n.º 5
0
		public void MultiPathINPC_Standard ()
		{
			var a = new INPC { Value = 0 };
			var b = new INPC { Value = 1 };
			var c = new INPC { Value = 2 };
			var d = new INPC { Value = 3 };

			a.Next = b;
			b.Next = c;
			c.Next = d;

			Rectangle r = new Rectangle ();
			r.SetBinding (Rectangle.WidthProperty, new Binding ("Next.Next.Next.Value"));
			
			r.DataContext = a;
			Assert.AreEqual (3, r.Width, "#1");
			
			d.Value = 10;
			Assert.AreEqual (10, r.Width, "#2");
		}
Exemplo n.º 6
0
		public void MentorTest_NotifyOnBindingException()
		{
			bool errored = false;
			var source = new INPC();
			var target = new CustomDependencyObject ();
			var mentor = new MentorElement { DataContext = source, MentoredCollection = new DependencyObjectCollection<object>() };
			mentor.MentoredCollection.Add(target);
			TestPanel.Children.Add(mentor);
			var binding = new Binding("SetterException") {
				Mode = BindingMode.TwoWay,
				ValidatesOnExceptions = true,
				NotifyOnValidationError = true
			};
			BindingOperations.SetBinding(target, CustomDependencyObject.WidthProperty, binding);
			Assert.AreEqual(100.0, target.Width, "#1");

			mentor.BindingValidationError += (o, e) => errored = true;
			Enqueue(() => {
				target.Width = 222;
				Assert.IsTrue(errored, "#2");
			});
			EnqueueTestComplete();
		}
Exemplo n.º 7
0
		public void TestOneWayBinding_GetterThrows ()
		{
			var source = new INPC ();
			var target = new Rectangle ();
			target.SetBinding (Rectangle.WidthProperty, new Binding ("GetterException") { ValidatesOnDataErrors = true, NotifyOnValidationError = true, ValidatesOnExceptions = true });
			Assert.DoesNotThrow (() => target.DataContext = source, "#1");
			Assert.AreEqual (0, Validation.GetErrors (target).Count, "#2");
		}