Exemplo n.º 1
0
        public void When_ValidBinding_And_Then_InvalidBinding_Inherited_Partial_Different_Binding_And_Fallback()
        {
            var o1 = new MyObjectWithExplicitDefaultValue();

            o1.SetBinding(MyObjectWithExplicitDefaultValue.MyPropertyProperty, new Binding()
            {
                Path = new PropertyPath("a")
            });

            var o2 = new MyObjectWithExplicitDefaultValue();

            o2.SetBinding(MyObjectWithExplicitDefaultValue.MyPropertyProperty, new Binding()
            {
                Path = new PropertyPath("b"), FallbackValue = 78
            });

            o1.SameTypeObject = o2;
            o2.SetParent(o1);

            o1.DataContext = new { a = 42, b = 43 };

            Assert.AreEqual(42, o1.MyProperty);
            Assert.AreEqual(43, o2.MyProperty);

            o1.DataContext = new { a = 42 };

            Assert.AreEqual(42, o1.MyProperty);
            Assert.AreEqual(78, o2.MyProperty);

            o1.DataContext = 42;

            Assert.AreEqual(77, o1.MyProperty);
            Assert.AreEqual(78, o2.MyProperty);
        }
Exemplo n.º 2
0
        public void When_ValidBinding_And_Then_InvalidBinding()
        {
            var sub   = new DependencyObjectCollection();
            var other = new MyObjectWithExplicitDefaultValue();

            other.SetBinding(MyObjectWithExplicitDefaultValue.MyPropertyProperty, new Binding()
            {
                Path = new PropertyPath("a")
            });

            sub.Add(other);

            sub.DataContext = new { a = 42 };

            Assert.AreEqual(42, other.MyProperty);

            sub.DataContext = 42;

            Assert.AreEqual(77, other.MyProperty);
        }