public void WhenDataContextChanges() { var textBox = new System.Windows.Controls.TextBox { DataContext = null }; var binding = new Binding { Path = new PropertyPath(DummyViewModel.NullableDoubleValuePropertyName), Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(textBox, Input.ValueProperty, binding); textBox.RaiseLoadedEvent(); Assert.AreEqual(null, textBox.GetSourceValueType()); var vm = new DummyViewModel { NullableDoubleValue = null }; textBox.DataContext = vm; Assert.AreEqual(typeof(double?), textBox.GetSourceValueType()); }
public void NullableDoubleNotNull() { var vm = new DummyViewModel { NullableDoubleValue = 1 }; var textBox = new System.Windows.Controls.TextBox { DataContext = vm }; var binding = new Binding { Path = new PropertyPath(DummyViewModel.NullableDoubleValuePropertyName), Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(textBox, Input.ValueProperty, binding); textBox.RaiseLoadedEvent(); textBox.RaiseEvent(new RoutedEventArgs(FrameworkElement.LoadedEvent)); Assert.AreEqual(typeof(double?), textBox.GetSourceValueType()); vm.NullableDoubleValue = 1; Assert.AreEqual(typeof(double?), textBox.GetSourceValueType()); }
public void WithConverterExplicit() { var vm = new DummyViewModel { StringIntValue = "1" }; var textBox = new System.Windows.Controls.TextBox { DataContext = vm }; var binding = new Binding { Converter = new StringToIntConverter(), Path = new PropertyPath(DummyViewModel.StringIntValuePropertyName), Mode = BindingMode.TwoWay }; textBox.SetSourceValueType(SourceValueTypes.Int32); BindingOperations.SetBinding(textBox, Input.ValueProperty, binding); DesignMode.IsInDesignModeForTests = true; textBox.RaiseLoadedEvent(); Assert.AreEqual(typeof(int), textBox.GetSourceValueType()); }