From 6c42a3cc0d62051cbbaef66bf75cc45871ae5d27 Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Thu, 2 Nov 2023 20:16:24 +0000 Subject: [PATCH] fix binding conversion error (#14557) - previously the dependency property of the numeric control was an integer, which would work, but would be raising a conversion error in the background --- .../Controls/NumericUpDownControl.xaml.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/DynamoCoreWpf/Views/PackageManager/Controls/NumericUpDownControl.xaml.cs b/src/DynamoCoreWpf/Views/PackageManager/Controls/NumericUpDownControl.xaml.cs index b7faecc70f1..a7efe608bf4 100644 --- a/src/DynamoCoreWpf/Views/PackageManager/Controls/NumericUpDownControl.xaml.cs +++ b/src/DynamoCoreWpf/Views/PackageManager/Controls/NumericUpDownControl.xaml.cs @@ -43,24 +43,25 @@ public string Watermark new FrameworkPropertyMetadata("0")); // The Value of the numerical up/down control. Bind to this property - public int Value + public string Value { - get { return (int)GetValue(ValueProperty); } + get { return (string)GetValue(ValueProperty); } set { SetValue(ValueProperty, value); } } // Using a DependencyProperty as the backing store for Value. public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", - typeof(int), + typeof(string), typeof(NumericUpDownControl), - new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnValuePropertyChanged))); + new FrameworkPropertyMetadata("0", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnValuePropertyChanged))); // Setting the input TextBox private static void OnValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var numericUpDownControl = d as NumericUpDownControl; numericUpDownControl.inputField.Text = e.NewValue.ToString(); + if (String.IsNullOrEmpty(e.NewValue.ToString())) return; if (numericUpDownControl.watermarkLabel.Visibility == Visibility.Visible) { numericUpDownControl.watermarkLabel.Visibility = Visibility.Collapsed; @@ -79,11 +80,11 @@ public NumericUpDownControl() #region UI utility functions private void spinnerUp_Click(object sender, RoutedEventArgs e) { - if (string.IsNullOrEmpty( inputField.Text)) + if (string.IsNullOrEmpty(inputField.Text)) { if (Int32.TryParse(watermarkLabel.Content as string, out int watermarkValue)) { - Value = ++watermarkValue; + Value = (++watermarkValue).ToString(); return; } else @@ -93,7 +94,7 @@ private void spinnerUp_Click(object sender, RoutedEventArgs e) } if (Int32.TryParse(inputField.Text, out int value)) { - Value = ++value; + Value = (++value).ToString(); }; } @@ -101,9 +102,9 @@ private void spinnerDown_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(inputField.Text)) { - if (Int32.TryParse(watermarkLabel.Content as string, out int watermarkValue)) + if (Int32.TryParse(watermarkLabel.Content as string, out int watermarkValue) && watermarkValue > 0) { - Value = --watermarkValue; + Value = (--watermarkValue).ToString(); return; } else @@ -113,9 +114,8 @@ private void spinnerDown_Click(object sender, RoutedEventArgs e) } if (Int32.TryParse(inputField.Text, out int value)) { - // Allows positive whole numbers - if (value <= 0) return; - Value = --value; + if (value == 0) return; + Value = (--value).ToString(); }; } @@ -133,7 +133,7 @@ private void inputField_TextChanged(object sender, TextChangedEventArgs e) { if (Int32.TryParse(inputField.Text, out int value)) { - Value = value; + Value = value.ToString(); }; }