コード例 #1
0
ファイル: Given_Binder.cs プロジェクト: wiltonlazary/uno
        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
ファイル: Given_Binder.cs プロジェクト: wiltonlazary/uno
        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
ファイル: Given_Binder.cs プロジェクト: wiltonlazary/uno
        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);
        }