コード例 #1
0
        public void SideEffectsOnChange()
        {
            var textBox = new System.Windows.Controls.TextBox();

            Assert.IsNull(BindingOperations.GetBindingExpression(textBox, System.Windows.Controls.TextBox.TextProperty));

            textBox.SetSourceValueType(typeof(int));
            textBox.RaiseLoadedEvent();
            Assert.NotNull(BindingOperations.GetBindingExpression(textBox, System.Windows.Controls.TextBox.TextProperty));

            Assert.AreEqual(DefaultNumberStyles.DefaultInteger, textBox.GetNumberStyles());
            Assert.AreEqual(DefaultStringConverters.Converters[typeof(int)], textBox.GetStringConverter());
            Assert.AreEqual(DefaultRules.Rules[typeof(int)], textBox.GetValidationRules());
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        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());
        }