fixed #276
This commit is contained in:
1 parent
40b09cc9c5
commit
1bc5a84959
1 file changed
+7
-11
@@ -25,6 +25,8 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
private TextBox _textBox;
|
private TextBox _textBox;
|
||||||
|
|
||||||
|
private bool _updateText;
|
||||||
|
|
||||||
#endregion Data
|
#endregion Data
|
||||||
|
|
||||||
public NumericUpDown()
|
public NumericUpDown()
|
||||||
@@ -34,23 +36,18 @@ namespace HandyControl.Controls
|
|||||||
if (IsReadOnly) return;
|
if (IsReadOnly) return;
|
||||||
|
|
||||||
Value += Increment;
|
Value += Increment;
|
||||||
_textBox.Text = CurrentText;
|
|
||||||
_textBox.Select(_textBox.Text.Length, 0);
|
|
||||||
}));
|
}));
|
||||||
CommandBindings.Add(new CommandBinding(ControlCommands.Next, (s, e) =>
|
CommandBindings.Add(new CommandBinding(ControlCommands.Next, (s, e) =>
|
||||||
{
|
{
|
||||||
if (IsReadOnly) return;
|
if (IsReadOnly) return;
|
||||||
|
|
||||||
Value -= Increment;
|
Value -= Increment;
|
||||||
_textBox.Text = CurrentText;
|
|
||||||
_textBox.Select(_textBox.Text.Length, 0);
|
|
||||||
}));
|
}));
|
||||||
CommandBindings.Add(new CommandBinding(ControlCommands.Clear, (s, e) =>
|
CommandBindings.Add(new CommandBinding(ControlCommands.Clear, (s, e) =>
|
||||||
{
|
{
|
||||||
if (IsReadOnly) return;
|
if (IsReadOnly) return;
|
||||||
|
|
||||||
SetCurrentValue(ValueProperty, ValueBoxes.Double0Box);
|
SetCurrentValue(ValueProperty, ValueBoxes.Double0Box);
|
||||||
_textBox.Text = string.Empty;
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Loaded += (s, e) => OnApplyTemplate();
|
Loaded += (s, e) => OnApplyTemplate();
|
||||||
@@ -98,7 +95,9 @@ namespace HandyControl.Controls
|
|||||||
if (!VerifyData()) return;
|
if (!VerifyData()) return;
|
||||||
if (double.TryParse(_textBox.Text, out var value))
|
if (double.TryParse(_textBox.Text, out var value))
|
||||||
{
|
{
|
||||||
|
_updateText = false;
|
||||||
Value = value;
|
Value = value;
|
||||||
|
_updateText = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,12 +116,10 @@ namespace HandyControl.Controls
|
|||||||
if (e.Key == Key.Up)
|
if (e.Key == Key.Up)
|
||||||
{
|
{
|
||||||
Value += Increment;
|
Value += Increment;
|
||||||
_textBox.Text = CurrentText;
|
|
||||||
}
|
}
|
||||||
else if (e.Key == Key.Down)
|
else if (e.Key == Key.Down)
|
||||||
{
|
{
|
||||||
Value -= Increment;
|
Value -= Increment;
|
||||||
_textBox.Text = CurrentText;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,8 +130,6 @@ namespace HandyControl.Controls
|
|||||||
if (_textBox.IsFocused && !IsReadOnly)
|
if (_textBox.IsFocused && !IsReadOnly)
|
||||||
{
|
{
|
||||||
Value += e.Delta > 0 ? Increment : -Increment;
|
Value += e.Delta > 0 ? Increment : -Increment;
|
||||||
_textBox.Text = CurrentText;
|
|
||||||
_textBox.Select(_textBox.Text.Length, 0);
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -173,9 +168,10 @@ namespace HandyControl.Controls
|
|||||||
{
|
{
|
||||||
var ctl = (NumericUpDown) d;
|
var ctl = (NumericUpDown) d;
|
||||||
var v = (double) e.NewValue;
|
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)
|
ctl.OnValueChanged(new FunctionEventArgs<double>(ValueChangedEvent, ctl)
|
||||||
|
|||||||
Reference in new issue
Block a user