Browse Source

Merge pull request #7252 from timunie/fix/ButtonSpinnerPointerWheel

Improve ButtonSpinner OnPointerWheel
pull/7270/head
Max Katz 5 years ago
committed by GitHub
parent
commit
0103106038
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/Avalonia.Controls/ButtonSpinner.cs
  2. 1
      src/Avalonia.Themes.Default/ButtonSpinner.xaml
  3. 1
      src/Avalonia.Themes.Fluent/Controls/ButtonSpinner.xaml

7
src/Avalonia.Controls/ButtonSpinner.cs

@ -1,4 +1,4 @@
using System; using System;
using Avalonia.Controls.Metadata; using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives; using Avalonia.Controls.Primitives;
using Avalonia.Data; using Avalonia.Data;
@ -196,13 +196,14 @@ namespace Avalonia.Controls
protected override void OnPointerWheelChanged(PointerWheelEventArgs e) protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
{ {
base.OnPointerWheelChanged(e); base.OnPointerWheelChanged(e);
if (!e.Handled && AllowSpin)
if (AllowSpin && IsKeyboardFocusWithin)
{ {
if (e.Delta.Y != 0) if (e.Delta.Y != 0)
{ {
var spinnerEventArgs = new SpinEventArgs(SpinEvent, (e.Delta.Y < 0) ? SpinDirection.Decrease : SpinDirection.Increase, true); var spinnerEventArgs = new SpinEventArgs(SpinEvent, (e.Delta.Y < 0) ? SpinDirection.Decrease : SpinDirection.Increase, true);
OnSpin(spinnerEventArgs); OnSpin(spinnerEventArgs);
e.Handled = spinnerEventArgs.Handled; e.Handled = true;
} }
} }
} }

1
src/Avalonia.Themes.Default/ButtonSpinner.xaml

@ -5,6 +5,7 @@
<Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}"/> <Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Focusable" Value="True"/>
</Style> </Style>
<Style Selector="ButtonSpinner /template/ RepeatButton"> <Style Selector="ButtonSpinner /template/ RepeatButton">
<Setter Property="Background" Value="Transparent"/> <Setter Property="Background" Value="Transparent"/>

1
src/Avalonia.Themes.Fluent/Controls/ButtonSpinner.xaml

@ -64,6 +64,7 @@
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" /> <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" /> <Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Focusable" Value="True"/>
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<DataValidationErrors> <DataValidationErrors>

Loading…
Cancel
Save