diff --git a/src/Avalonia.Controls/DateTimePickers/LoopingSelectorItem.cs b/src/Avalonia.Controls/DateTimePickers/LoopingSelectorItem.cs index 8e1d242561..3b53cf6795 100644 --- a/src/Avalonia.Controls/DateTimePickers/LoopingSelectorItem.cs +++ b/src/Avalonia.Controls/DateTimePickers/LoopingSelectorItem.cs @@ -1,8 +1,7 @@ -using Avalonia; -using Avalonia.Controls; +using System; +using Avalonia.Controls.Mixins; using Avalonia.Input; using Avalonia.Interactivity; -using System; namespace Avalonia.Controls.Primitives { @@ -13,30 +12,19 @@ namespace Avalonia.Controls.Primitives { static LoopingSelectorItem() { - IsPressedProperty.Changed.AddClassHandler((x, e) => x.OnIsPressedChanged(e)); + PressedMixin.Attach(); IsSelectedProperty.Changed.AddClassHandler((x, e) => x.OnIsSelectedChanged(e)); } - /// - /// Defines the Property - /// - public static readonly StyledProperty IsPressedProperty = - AvaloniaProperty.Register("IsPressed"); - /// /// Defines the Property /// internal static readonly StyledProperty IsSelectedProperty = - AvaloniaProperty.Register("IsSelected"); + AvaloniaProperty.Register(nameof(IsSelected)); - /// - /// Gets whether the item is currently pressed - /// - public bool IsPressed - { - get => GetValue(IsPressedProperty); - private set => SetValue(IsPressedProperty, value); - } + + public static readonly RoutedEvent SelectedEvent = + RoutedEvent.Register(nameof(Selected), RoutingStrategies.Bubble); internal bool IsSelected { @@ -44,37 +32,12 @@ namespace Avalonia.Controls.Primitives set => SetValue(IsSelectedProperty, value); } - private void OnIsPressedChanged(AvaloniaPropertyChangedEventArgs e) - { - PseudoClasses.Set(":pressed", (bool)e.NewValue); - } - - protected override void OnPointerPressed(PointerPressedEventArgs e) - { - base.OnPointerPressed(e); - if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) - { - IsPressed = true; - } - } - - protected override void OnPointerMoved(PointerEventArgs e) - { - base.OnPointerMoved(e); - if (IsPressed) - { - var pt = e.GetPosition(this); - if (pt.X < 0 || pt.Y < 0 || pt.X > Bounds.Width || pt.Y > Bounds.Height) - IsPressed = false; - } - } - protected override void OnPointerReleased(PointerReleasedEventArgs e) { base.OnPointerReleased(e); - if (IsPressed && e.GetCurrentPoint(this).Properties.PointerUpdateKind == PointerUpdateKind.LeftButtonReleased) + + if (e.GetCurrentPoint(this).Properties.PointerUpdateKind == PointerUpdateKind.LeftButtonReleased) { - IsPressed = false; //The selection event only raises when invoked by pointer events RaiseEvent(new RoutedEventArgs(SelectedEvent, this)); } @@ -86,9 +49,6 @@ namespace Avalonia.Controls.Primitives PseudoClasses.Set(":selected", newValue); } - public static readonly RoutedEvent SelectedEvent = - RoutedEvent.Register("Selected", RoutingStrategies.Bubble); - public event EventHandler Selected { add => AddHandler(SelectedEvent, value);