예제 #1
0
        public void When_Inherited_data_Context_and_Changed()
        {
            var SUT = new Target1();

            var child = new Target2(SUT);

            child.SetBinding(Target2.DataContextProperty, new Binding("Child"));
            child.SetBinding("TargetValue", new Binding("Value"));
            SUT.ChildrenBinders.Add(child);

            var source = new MySource();

            SUT.DataContext = source;

            Assert.AreEqual(42, child.TargetValue);
            Assert.AreEqual(1, child.TargetValueSetCount);
            Assert.AreEqual(1, SUT.DataContextChangedCount);
            Assert.AreEqual(1, child.DataContextChangedCount);

            source.Child = new MySource2(44);
            Assert.AreEqual(44, child.TargetValue);
            Assert.AreEqual(2, child.TargetValueSetCount);
            Assert.AreEqual(1, SUT.DataContextChangedCount);
            Assert.AreEqual(2, child.DataContextChangedCount);
        }
예제 #2
0
        public void When_Direct_data_Context_binding()
        {
            var SUT = new Target1();

            var child = new Target2();

            // Bypass the inheritance
            child.SetBinding(Target1.DataContextProperty, new Binding("Child"));

            child.SetBinding(Target2.TargetValueProperty, new Binding("Value"));

            SUT.ChildrenBinders.Add(child);

            var source = new MySource();

            SUT.DataContext = source;

            Assert.AreEqual(42, child.TargetValue);
            Assert.AreEqual(1, child.TargetValueSetCount);
        }
예제 #3
0
        public void When_Inherited_data_Context_And_Converter()
        {
            var SUT = new Target1();

            var child = new Target2(SUT);

            child.SetBinding(Target2.DataContextProperty, new Binding("Child"));
            child.SetBinding("TargetValue", new Binding("Value", converter: new OppositeConverter()));
            SUT.ChildrenBinders.Add(child);

            var source = new MySource();

            SUT.DataContext = source;

            Assert.AreEqual(-42, child.TargetValue);
            Assert.AreEqual(1, child.TargetValueSetCount);

            source.Child = new MySource2(43);
            Assert.AreEqual(-43, child.TargetValue);
            Assert.AreEqual(2, child.TargetValueSetCount);
        }