示例#1
0
        public void When_ExplicitUpdateSourceTrigger_UpdateSource()
        {
            var source = new MyBindingSource {
                IntValue = 42
            };
            var target = new MyControl();

            target.SetBinding(MyControl.MyPropertyProperty, new Binding {
                Source = source, Path = nameof(MyBindingSource.IntValue), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.Explicit
            });

            var sut = target.GetBindingExpression(MyControl.MyPropertyProperty);

            Assert.AreEqual(42, source.IntValue);
            Assert.AreEqual(42, target.MyProperty);

            target.MyProperty = -42;
            sut.UpdateSource();

            Assert.AreEqual(-42, source.IntValue);
            Assert.AreEqual(-42, target.MyProperty);
        }