From 1bc5a84959db1dfbba6d04a43df2a2a525ce5d69 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Tue, 7 Jan 2020 00:41:17 +0800 Subject: [PATCH] fixed #276 --- .../Controls/Input/NumericUpDown.cs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs index eac6fd1a..c18bbb0a 100644 --- a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs +++ b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs @@ -25,6 +25,8 @@ namespace HandyControl.Controls private TextBox _textBox; + private bool _updateText; + #endregion Data public NumericUpDown() @@ -34,23 +36,18 @@ namespace HandyControl.Controls if (IsReadOnly) return; Value += Increment; - _textBox.Text = CurrentText; - _textBox.Select(_textBox.Text.Length, 0); })); CommandBindings.Add(new CommandBinding(ControlCommands.Next, (s, e) => { if (IsReadOnly) return; Value -= Increment; - _textBox.Text = CurrentText; - _textBox.Select(_textBox.Text.Length, 0); })); CommandBindings.Add(new CommandBinding(ControlCommands.Clear, (s, e) => { if (IsReadOnly) return; SetCurrentValue(ValueProperty, ValueBoxes.Double0Box); - _textBox.Text = string.Empty; })); Loaded += (s, e) => OnApplyTemplate(); @@ -98,7 +95,9 @@ namespace HandyControl.Controls if (!VerifyData()) return; if (double.TryParse(_textBox.Text, out var value)) { + _updateText = false; Value = value; + _updateText = true; } } @@ -117,12 +116,10 @@ namespace HandyControl.Controls if (e.Key == Key.Up) { Value += Increment; - _textBox.Text = CurrentText; } else if (e.Key == Key.Down) { Value -= Increment; - _textBox.Text = CurrentText; } } @@ -133,8 +130,6 @@ namespace HandyControl.Controls if (_textBox.IsFocused && !IsReadOnly) { Value += e.Delta > 0 ? Increment : -Increment; - _textBox.Text = CurrentText; - _textBox.Select(_textBox.Text.Length, 0); e.Handled = true; } } @@ -173,9 +168,10 @@ namespace HandyControl.Controls { var ctl = (NumericUpDown) d; var v = (double) e.NewValue; - if (ctl._textBox != null) + if (ctl._updateText && ctl._textBox != null) { - ctl._textBox.Text = v.ToString(); + ctl._textBox.Text = ctl.CurrentText; + ctl._textBox.Select(ctl._textBox.Text.Length, 0); } ctl.OnValueChanged(new FunctionEventArgs(ValueChangedEvent, ctl)