fix: NumericUpDown issue.
This commit is contained in:
1 parent
d664289be6
commit
8a66f92089
1 file changed
+20
-8
@@ -58,7 +58,7 @@ public class NumericUpDown : Control
|
|||||||
if (_textBox != null)
|
if (_textBox != null)
|
||||||
{
|
{
|
||||||
_textBox.SetBinding(SelectionBrushProperty, new Binding(SelectionBrushProperty.Name) { Source = this });
|
_textBox.SetBinding(SelectionBrushProperty, new Binding(SelectionBrushProperty.Name) { Source = this });
|
||||||
#if !(NET40 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472)
|
#if NET48_OR_GREATER
|
||||||
_textBox.SetBinding(SelectionTextBrushProperty, new Binding(SelectionTextBrushProperty.Name) { Source = this });
|
_textBox.SetBinding(SelectionTextBrushProperty, new Binding(SelectionTextBrushProperty.Name) { Source = this });
|
||||||
#endif
|
#endif
|
||||||
_textBox.SetBinding(SelectionOpacityProperty, new Binding(SelectionOpacityProperty.Name) { Source = this });
|
_textBox.SetBinding(SelectionOpacityProperty, new Binding(SelectionOpacityProperty.Name) { Source = this });
|
||||||
@@ -66,19 +66,31 @@ public class NumericUpDown : Control
|
|||||||
|
|
||||||
_textBox.PreviewKeyDown += TextBox_PreviewKeyDown;
|
_textBox.PreviewKeyDown += TextBox_PreviewKeyDown;
|
||||||
_textBox.TextChanged += TextBox_TextChanged;
|
_textBox.TextChanged += TextBox_TextChanged;
|
||||||
|
_textBox.LostFocus += TextBox_LostFocus;
|
||||||
_textBox.Text = CurrentText;
|
_textBox.Text = CurrentText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(_textBox.Text))
|
||||||
|
{
|
||||||
|
SetCurrentValue(ValueProperty, ValueBoxes.Double0Box);
|
||||||
|
}
|
||||||
|
else if (double.TryParse(_textBox.Text, out double value))
|
||||||
|
{
|
||||||
|
SetCurrentValue(ValueProperty, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
|
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(_textBox.Text))
|
if (double.TryParse(_textBox.Text, out double value))
|
||||||
{
|
{
|
||||||
SetCurrentValue(ValueProperty, ValueBoxes.Int0Box);
|
if (value >= Minimum && value <= Maximum)
|
||||||
}
|
{
|
||||||
else if (double.TryParse(_textBox.Text, out var value))
|
SetCurrentValue(ValueProperty, value);
|
||||||
{
|
}
|
||||||
SetCurrentValue(ValueProperty, value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,7 +340,7 @@ public class NumericUpDown : Control
|
|||||||
set => SetValue(SelectionBrushProperty, value);
|
set => SetValue(SelectionBrushProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !(NET40 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472)
|
#if NET48_OR_GREATER
|
||||||
|
|
||||||
public static readonly DependencyProperty SelectionTextBrushProperty =
|
public static readonly DependencyProperty SelectionTextBrushProperty =
|
||||||
TextBoxBase.SelectionTextBrushProperty.AddOwner(typeof(NumericUpDown));
|
TextBoxBase.SelectionTextBrushProperty.AddOwner(typeof(NumericUpDown));
|
||||||
|
|||||||
Reference in new issue
Block a user