diff --git a/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs b/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs index 673d5c5..ec4aeff 100644 --- a/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs +++ b/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs @@ -30,6 +30,12 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl private Point? _point; protected internal bool _updateFromTextInput; + + protected internal bool _canIncrease = true; + + protected internal bool _canDecrease = true; + + public static readonly StyledProperty AllowDragProperty = AvaloniaProperty.Register( nameof(AllowDrag), defaultValue: false); @@ -256,11 +262,13 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl int d = GetDelta(delta.Value); if (d > 0) { - Increase(); + if (_canIncrease) + Increase(); } else if (d < 0) { - Decrease(); + if (_canDecrease) + Decrease(); } _point = point; } @@ -332,7 +340,7 @@ public abstract class NumericUpDownBase : NumericUpDown where T : struct, ICo if (text.StartsWith("0X") || text.StartsWith("0x")) // support 0x hex while user input { text = text.Substring(2); - } + } else if (text.StartsWith("h") || text.StartsWith("H")) // support hex while user input { text = text.Substring(1); @@ -511,6 +519,8 @@ public abstract class NumericUpDownBase : NumericUpDown where T : struct, ICo protected override void SetValidSpinDirection() { var validDirection = ValidSpinDirections.None; + _canIncrease = false; + _canDecrease = false; if (!IsReadOnly) { if (Value is null) @@ -520,11 +530,13 @@ public abstract class NumericUpDownBase : NumericUpDown where T : struct, ICo if (Value.HasValue && Value.Value.CompareTo(Maximum) < 0) { validDirection |= ValidSpinDirections.Increase; + _canIncrease = true; } if (Value.HasValue && Value.Value.CompareTo(Minimum) > 0) { validDirection |= ValidSpinDirections.Decrease; + _canDecrease = true; } } if (_spinner != null) @@ -553,28 +565,28 @@ public abstract class NumericUpDownBase : NumericUpDown where T : struct, ICo } if (!Equals(newValue, Value)) { - SetCurrentValue(ValueProperty, newValue); - } - } - catch - { - parsedTextIsValid = false; - } - } - - if (!_updateFromTextInput) - { - if (forceTextUpdate) - { - var newText = ConvertValueToText(Value); - if (_textBox != null && !Equals(_textBox.Text, newText)) - { - _textBox.Text = newText; - _textBox.CaretIndex = newText?.Length ?? 0; - } - } - } - + SetCurrentValue(ValueProperty, newValue); + } + } + catch + { + parsedTextIsValid = false; + } + } + + if (!_updateFromTextInput) + { + if (forceTextUpdate) + { + var newText = ConvertValueToText(Value); + if (_textBox != null && !Equals(_textBox.Text, newText)) + { + _textBox.Text = newText; + _textBox.CaretIndex = newText?.Length ?? 0; + } + } + } + if (_updateFromTextInput && !parsedTextIsValid) { if (_spinner is not null)