|
|
|
@ -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<LoopingSelectorItem>((x, e) => x.OnIsPressedChanged(e)); |
|
|
|
PressedMixin.Attach<LoopingSelectorItem>(); |
|
|
|
IsSelectedProperty.Changed.AddClassHandler<LoopingSelectorItem>((x, e) => x.OnIsSelectedChanged(e)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Defines the <see cref="IsPressed"/> Property
|
|
|
|
/// </summary>
|
|
|
|
public static readonly StyledProperty<bool> IsPressedProperty = |
|
|
|
AvaloniaProperty.Register<LoopingSelectorItem, bool>("IsPressed"); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Defines the <see cref="IsSelected"/> Property
|
|
|
|
/// </summary>
|
|
|
|
internal static readonly StyledProperty<bool> IsSelectedProperty = |
|
|
|
AvaloniaProperty.Register<LoopingSelectorItem, bool>("IsSelected"); |
|
|
|
AvaloniaProperty.Register<LoopingSelectorItem, bool>(nameof(IsSelected)); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets whether the item is currently pressed
|
|
|
|
/// </summary>
|
|
|
|
public bool IsPressed |
|
|
|
{ |
|
|
|
get => GetValue(IsPressedProperty); |
|
|
|
private set => SetValue(IsPressedProperty, value); |
|
|
|
} |
|
|
|
|
|
|
|
public static readonly RoutedEvent<RoutedEventArgs> SelectedEvent = |
|
|
|
RoutedEvent.Register<LoopingSelectorItem, RoutedEventArgs>(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<RoutedEventArgs> SelectedEvent = |
|
|
|
RoutedEvent.Register<LoopingSelectorItem, RoutedEventArgs>("Selected", RoutingStrategies.Bubble); |
|
|
|
|
|
|
|
public event EventHandler<RoutedEventArgs> Selected |
|
|
|
{ |
|
|
|
add => AddHandler(SelectedEvent, value); |
|
|
|
|