mirror of
https://gitee.com/handyorg/HandyControl.git
synced 2024-12-02 20:07:56 +08:00
fixed #276
This commit is contained in:
parent
40b09cc9c5
commit
1bc5a84959
@ -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<double>(ValueChangedEvent, ctl)
|
||||
|
Loading…
Reference in New Issue
Block a user