Ejemplo n.º 1
0
        public void When_Modified_From_Callback_And_TwoWay()
        {
            var dp1 = new MyDP();
            var dp2 = new MyDP();

            var binding = new Binding
            {
                Source = dp1,
                Path   = new PropertyPath(nameof(MyDP.MyInt)),
                Mode   = BindingMode.TwoWay
            };

            BindingOperations.SetBinding(dp2, MyDP.MyIntProperty, binding);
            var callbackCount = 0;

            dp1.RegisterPropertyChangedCallback(MyDP.MyIntProperty, OnMyIntChanged);

            dp2.MyInt = 11;

            Assert.AreEqual(42, dp1.MyInt);
            Assert.AreEqual(11, dp2.MyInt);

            Assert.AreEqual(2, callbackCount);

            void OnMyIntChanged(DependencyObject sender, DependencyProperty dpInner)
            {
                callbackCount++;
                (sender as MyDP).MyInt = 42;
            }
        }
Ejemplo n.º 2
0
        public void When_Modified_From_Callback()
        {
            var dp            = new MyDP();
            var callbackCount = 0;

            dp.RegisterPropertyChangedCallback(MyDP.MyIntProperty, OnMyIntChanged);

            dp.MyInt = 11;

            Assert.AreEqual(42, dp.MyInt);

            Assert.AreEqual(2, callbackCount);

            void OnMyIntChanged(DependencyObject sender, DependencyProperty dpInner)
            {
                callbackCount++;
                (sender as MyDP).MyInt = 42;
            }
        }