예제 #1
0
        public void MyTestMethod()
        {
            var a = new MyDependencyObject()
            {
                PropName = "a"
            };
            var b = new MyDependencyObject()
            {
                PropName = "b"
            };
            var converter = new MyConverter();

            b.SetBinding(
                MyDependencyObject.MyIntegerProperty,
                new Windows.UI.Xaml.Data.Binding
            {
                Path      = new PropertyPath(nameof(b.MyInteger)),
                Converter = converter,
                Source    = a,
                Mode      = BindingMode.TwoWay
            }
                );

            Assert.AreEqual(1, converter.ConvertCallCount);
            Assert.AreEqual(0, converter.ConvertBackCallCount);
            Assert.AreEqual(1, b.MyInteger);

            Debug.WriteLine("setting a.MyInteger = 1");
            a.MyInteger = 1;
            Assert.AreEqual(2, converter.ConvertCallCount);
            Assert.AreEqual(0, converter.ConvertBackCallCount);
            Assert.AreEqual(1, a.MyInteger);
            Assert.AreEqual(2, b.MyInteger);

            Debug.WriteLine("setting b.MyInteger = 2");
            b.MyInteger = 2;
            Assert.AreEqual(2, converter.ConvertCallCount);
            Assert.AreEqual(0, converter.ConvertBackCallCount);
            Assert.AreEqual(1, a.MyInteger);
            Assert.AreEqual(2, b.MyInteger);

            Debug.WriteLine("setting b.MyInteger = 3");
            b.MyInteger = 3;

            Assert.AreEqual(3, converter.ConvertCallCount);
            Assert.AreEqual(1, converter.ConvertBackCallCount);
            Assert.AreEqual(3, a.MyInteger);
            Assert.AreEqual(3, b.MyInteger);

            a.MyInteger = 42;
            Assert.AreEqual(2, converter.ConvertCallCount);
            Assert.AreEqual(2, converter.ConvertBackCallCount);
            Assert.AreEqual(42, a.MyInteger);
            Assert.AreEqual(42, b.MyInteger);
        }
예제 #2
0
        public void When_TwoWay_Converted()
        {
            var a = new MyDependencyObject()
            {
                PropName = "a"
            };
            var b = new MyDependencyObject()
            {
                PropName = "b"
            };
            var converter = new MyConverter();

            BindingOperations.SetBinding(b,
                                         MyDependencyObject.MyIntegerProperty,
                                         new Windows.UI.Xaml.Data.Binding
            {
                Path      = new PropertyPath(nameof(b.MyInteger)),
                Converter = converter,
                Source    = a,
                Mode      = BindingMode.TwoWay
            }
                                         );

            Assert.AreEqual(1, converter.ConvertCallCount);
            Assert.AreEqual(0, converter.ConvertBackCallCount);
            Assert.AreEqual(1, b.MyInteger);

            a.MyInteger = 1;
            Assert.AreEqual(2, converter.ConvertCallCount);
            Assert.AreEqual(0, converter.ConvertBackCallCount);
            Assert.AreEqual(1, a.MyInteger);
            Assert.AreEqual(2, b.MyInteger);

            b.MyInteger = 2;
            Assert.AreEqual(2, converter.ConvertCallCount);
            Assert.AreEqual(0, converter.ConvertBackCallCount);
            Assert.AreEqual(1, a.MyInteger);
            Assert.AreEqual(2, b.MyInteger);

            b.MyInteger = 3;

            Assert.AreEqual(2, converter.ConvertCallCount);
            Assert.AreEqual(1, converter.ConvertBackCallCount);
            Assert.AreEqual(3, a.MyInteger);
            Assert.AreEqual(3, b.MyInteger);

            a.MyInteger = 42;
            Assert.AreEqual(3, converter.ConvertCallCount);
            Assert.AreEqual(1, converter.ConvertBackCallCount);
            Assert.AreEqual(42, a.MyInteger);
            Assert.AreEqual(43, b.MyInteger);
        }