public void ClearingABinding() { var source = new BindingTestSource { SourceProperty = 100 }; var target = new BindingTestTarget(); var binding = new Binding("SourceProperty") { Source = source, Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(target, BindingTestTarget.TargetPropertyProperty, binding); var bindingOperation = BindingOperations.GetBindingExpression(target, BindingTestTarget.TargetPropertyProperty); Assert.AreEqual("100", target.TargetProperty); BindingOperations.ClearBinding(target, BindingTestTarget.TargetPropertyProperty); target.TargetProperty = "10"; Assert.AreEqual("10", target.TargetProperty); Assert.AreEqual(100, source.SourceProperty); Assert.IsFalse(SWC.Validation.GetHasError(target)); }
public void DataItemIsByDefault() { var target = new BindingTestTarget(); var binding = new Binding("SourceProperty") { Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(target, BindingTestTarget.TargetPropertyProperty, binding); Assert.IsNull(target.TargetProperty); var bindingExpression = BindingOperations.GetBindingExpression(target, BindingTestTarget.TargetPropertyProperty); Assert.IsNull(bindingExpression.DataItem); Assert.AreEqual("SourceProperty", bindingExpression.ParentBinding.Path.Path); }
public void DataItemIsDataContextIfSourceIsNotExplicitlySet() { var target = new BindingTestTarget(); var sourceDataContext = new BindingTestSource(); target.DataContext = sourceDataContext; var binding = new Binding("SourceProperty") { Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(target, BindingTestTarget.TargetPropertyProperty, binding); var bindingExpression = BindingOperations.GetBindingExpression(target, BindingTestTarget.TargetPropertyProperty); Assert.AreSame(sourceDataContext, bindingExpression.DataItem); Assert.AreEqual("SourceProperty", bindingExpression.ParentBinding.Path.Path); }
public void BindingLogsErrorIfValueIfValueConversionFails() { var source = new BindingTestSource { SourceProperty = 100 }; var target = new BindingTestTarget(); var binding = new Binding("SourceProperty") { Source = source, Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(target, BindingTestTarget.TargetPropertyProperty, binding); Assert.AreEqual("100", target.TargetProperty); target.TargetProperty = "zzz"; Assert.AreEqual("zzz", target.TargetProperty); Assert.AreEqual(100, source.SourceProperty); Assert.IsTrue(SWC.Validation.GetHasError(target)); }
public void BindingSetsValue() { var source = new BindingTestSource { SourceProperty = 100 }; var target = new BindingTestTarget(); var binding = new Binding("SourceProperty") { Source = source, Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(target, BindingTestTarget.TargetPropertyProperty, binding); Assert.AreEqual("100", target.TargetProperty); target.TargetProperty = "10"; Assert.AreEqual("10", target.TargetProperty); Assert.AreEqual(10, source.SourceProperty); Assert.IsFalse(SWC.Validation.GetHasError(target)); }
public void BindingForPropertyInvalidPathIsIgnoredIfNotThrowingExceptions() { var source = new BindingTestSource { SourceProperty = 100 }; var target = new BindingTestTarget(); var binding = new Binding("InvalidProperty") { Source = source, Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(target, BindingTestTarget.TargetPropertyProperty, binding); target.TargetProperty = "10"; Assert.AreEqual("10", target.TargetProperty); Assert.AreEqual(100, source.SourceProperty); Assert.IsFalse(SWC.Validation.GetHasError(target)); }
public void DataItemIsSourceIfExplicitlySet() { var target = new BindingTestTarget(); var sourceExplicit = new BindingTestSource(); var sourceDataContext = new BindingTestSource(); target.DataContext = sourceDataContext; var binding = new Binding("SourceProperty") { Source = sourceExplicit, Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(target, BindingTestTarget.TargetPropertyProperty, binding); var bindingExpression = BindingOperations.GetBindingExpression(target, BindingTestTarget.TargetPropertyProperty); Assert.AreSame(sourceExplicit, bindingExpression.DataItem); Assert.AreEqual("SourceProperty", bindingExpression.ParentBinding.Path.Path); }