From f4d949460a684b87d3fb11f35ee8175065dd6d47 Mon Sep 17 00:00:00 2001 From: seedtyx Date: Mon, 8 Jun 2020 14:48:30 +0800 Subject: [PATCH] fix bug #393 fix bug #393 --- .../Controls/Input/NumericUpDown.cs | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs index 53975dd3..b153a4b2 100644 --- a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs +++ b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -178,11 +178,7 @@ namespace HandyControl.Controls { var ctl = (NumericUpDown) d; var v = (double) e.NewValue; - if (ctl._updateText && ctl._textBox != null) - { - ctl._textBox.Text = ctl.CurrentText; - ctl._textBox.Select(ctl._textBox.Text.Length, 0); - } + ctl.SetText(); ctl.OnValueChanged(new FunctionEventArgs(ValueChangedEvent, ctl) { @@ -190,6 +186,15 @@ namespace HandyControl.Controls }); } + private void SetText() + { + if (_updateText && _textBox != null) + { + _textBox.Text = CurrentText; + _textBox.Select(_textBox.Text.Length, 0); + } + } + private static object CoerceValue(DependencyObject d, object basevalue) { var ctl = (NumericUpDown)d; @@ -214,8 +219,12 @@ namespace HandyControl.Controls /// public double Value { - get => (double) GetValue(ValueProperty); - set => SetValue(ValueProperty, value); + get => (double)GetValue(ValueProperty); + set + { + SetValue(ValueProperty, value); + SetText(); + } } /// @@ -430,4 +439,4 @@ namespace HandyControl.Controls return result.Data; } } -} \ No newline at end of file +}