Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pm binding conversion error #14557

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -93,17 +94,17 @@ private void spinnerUp_Click(object sender, RoutedEventArgs e)
}
if (Int32.TryParse(inputField.Text, out int value))
{
Value = ++value;
Value = (++value).ToString();
};
}

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
Expand All @@ -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();
};
}

Expand All @@ -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();
};
}

Expand Down
Loading