diff --git a/demo/Ursa.Demo/Pages/NumericUpDownDemo.axaml b/demo/Ursa.Demo/Pages/NumericUpDownDemo.axaml index 379ac2d..33d5bf7 100644 --- a/demo/Ursa.Demo/Pages/NumericUpDownDemo.axaml +++ b/demo/Ursa.Demo/Pages/NumericUpDownDemo.axaml @@ -14,13 +14,13 @@ - + - + diff --git a/src/Ursa.Themes.Semi/Controls/NumericUpDown.axaml b/src/Ursa.Themes.Semi/Controls/NumericUpDown.axaml index aeb4765..499de51 100644 --- a/src/Ursa.Themes.Semi/Controls/NumericUpDown.axaml +++ b/src/Ursa.Themes.Semi/Controls/NumericUpDown.axaml @@ -38,8 +38,7 @@ VerticalAlignment="Stretch" Background="Transparent" Cursor="SizeAll" - IsVisible="{TemplateBinding IsTextEditable, - Converter={x:Static BoolConverters.Not}}" /> + IsVisible="{TemplateBinding AllowDrag}" /> diff --git a/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs b/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs index 2d90ede..0599617 100644 --- a/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs +++ b/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs @@ -27,13 +27,13 @@ public abstract class NumericUpDown : TemplatedControl private Point? _point; protected internal bool _updateFromTextInput; - public static readonly StyledProperty IsTextEditableProperty = AvaloniaProperty.Register( - nameof(IsTextEditable), defaultValue: true); + public static readonly StyledProperty AllowDragProperty = AvaloniaProperty.Register( + nameof(AllowDrag), defaultValue: false); - public bool IsTextEditable + public bool AllowDrag { - get => GetValue(IsTextEditableProperty); - set => SetValue(IsTextEditableProperty, value); + get => GetValue(AllowDragProperty); + set => SetValue(AllowDragProperty, value); } public static readonly StyledProperty IsReadOnlyProperty = AvaloniaProperty.Register( @@ -183,6 +183,10 @@ public abstract class NumericUpDown : TemplatedControl { CommitInput(true); base.OnLostFocus(e); + if(AllowDrag && _dragPanel is not null) + { + _dragPanel.IsVisible = true; + } } protected override void OnKeyDown(KeyEventArgs e) @@ -192,11 +196,23 @@ public abstract class NumericUpDown : TemplatedControl var commitSuccess = CommitInput(true); e.Handled = !commitSuccess; } + + if (e.Key == Key.Escape) + { + if (AllowDrag && _dragPanel is not null) + { + _dragPanel.IsVisible = true; + } + } } private void OnDragPanelPointerPressed(object sender, PointerPressedEventArgs e) { _point = e.GetPosition(this); + if (e.ClickCount == 2 && _dragPanel is not null && AllowDrag) + { + _dragPanel.IsVisible = false; + } _textBox?.Focus(); } @@ -207,7 +223,7 @@ public abstract class NumericUpDown : TemplatedControl private void OnDragPanelPointerMoved(object sender, PointerEventArgs e) { - if (IsTextEditable) return; + if (!AllowDrag) return; if(!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return; var point = e.GetPosition(this); var delta = point - _point; @@ -420,6 +436,7 @@ public abstract class NumericUpDownBase: NumericUpDown where T: struct, IComp { _textBox.Text = ConvertValueToText(Value); } + SetValidSpinDirection(); } protected virtual T? Clamp(T? value, T max, T min)