예제 #1
0
        public void OneWayBinding()
        {
            var vm      = new PropertyChangedViewModel();
            var control = new DependencyPropertyBehaviorTestControl()
            {
                DataContext = vm
            };

            vm.SetReadOnlyProperty("1");
            var behavior = new DependencyPropertyBehavior()
            {
                PropertyName = "Property"
            };

            BindingOperations.SetBinding(behavior, DependencyPropertyBehavior.BindingProperty, new Binding("ReadOnlyProperty")
            {
                Mode = BindingMode.OneWay
            });
            Interaction.GetBehaviors(control).Add(behavior);
            Assert.AreEqual(1, control.propertyChangedCounter);
            Assert.AreEqual("1", control.Property);
            vm.SetReadOnlyProperty("2");
            Assert.AreEqual(2, control.propertyChangedCounter);
            Assert.AreEqual("2", control.Property);
        }
 public void OneWayBinding() {
     var vm = new PropertyChangedViewModel();
     var control = new DependencyPropertyBehaviorTestControl() { DataContext = vm };
     vm.SetReadOnlyProperty("1");
     var behavior = new DependencyPropertyBehavior() { PropertyName = "Property" };
     BindingOperations.SetBinding(behavior, DependencyPropertyBehavior.BindingProperty, new Binding("ReadOnlyProperty") { Mode = BindingMode.OneWay });
     Interaction.GetBehaviors(control).Add(behavior);
     Assert.AreEqual(1, control.propertyChangedCounter);
     Assert.AreEqual("1", control.Property);
     vm.SetReadOnlyProperty("2");
     Assert.AreEqual(2, control.propertyChangedCounter);
     Assert.AreEqual("2", control.Property);
 }