This commit is contained in:
Wiesław Šoltés 2024-04-24 19:26:13 +02:00
Родитель 752fbbf5be
Коммит 59a7f2d04d
40 изменённых файлов: 382 добавлений и 324 удалений

Просмотреть файл

@ -2,6 +2,7 @@ using System.Reactive.Disposables;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Threading;
using Avalonia.VisualTree;
namespace Avalonia.Xaml.Interactions.Custom;
@ -9,53 +10,8 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ButtonExecuteCommandOnKeyDownBehavior : AttachedToVisualTreeBehavior<Button>
public class ButtonExecuteCommandOnKeyDownBehavior : ExecuteCommandOnKeyBehaviorBase
{
/// <summary>
///
/// </summary>
public static readonly StyledProperty<bool> IsEnabledProperty =
AvaloniaProperty.Register<ButtonExecuteCommandOnKeyDownBehavior, bool>(nameof(IsEnabled));
/// <summary>
///
/// </summary>
public static readonly StyledProperty<Key?> KeyProperty =
AvaloniaProperty.Register<ButtonExecuteCommandOnKeyDownBehavior, Key?>(nameof(Key));
/// <summary>
///
/// </summary>
public static readonly StyledProperty<KeyGesture?> GestureProperty =
AvaloniaProperty.Register<ButtonExecuteCommandOnKeyDownBehavior, KeyGesture?>(nameof(Gesture));
/// <summary>
///
/// </summary>
public bool IsEnabled
{
get => GetValue(IsEnabledProperty);
set => SetValue(IsEnabledProperty, value);
}
/// <summary>
///
/// </summary>
public Key? Key
{
get => GetValue(KeyProperty);
set => SetValue(KeyProperty, value);
}
/// <summary>
///
/// </summary>
public KeyGesture? Gesture
{
get => GetValue(GestureProperty);
set => SetValue(GestureProperty, value);
}
/// <summary>
///
/// </summary>
@ -79,12 +35,12 @@ public class ButtonExecuteCommandOnKeyDownBehavior : AttachedToVisualTreeBehavio
return;
}
if (AssociatedObject is { } button)
if (AssociatedObject is Button button)
{
ExecuteCommand(button);
}
}
private bool ExecuteCommand(Button button)
{
if (!IsEnabled)
@ -102,6 +58,16 @@ public class ButtonExecuteCommandOnKeyDownBehavior : AttachedToVisualTreeBehavio
return false;
}
if (FocusTopLevel)
{
Dispatcher.UIThread.Post(() => (AssociatedObject?.GetVisualRoot() as TopLevel)?.Focus());
}
if (FocusControl is { } focusControl)
{
Dispatcher.UIThread.Post(() => focusControl.Focus());
}
button.Command.Execute(button.CommandParameter);
return true;
}

Просмотреть файл

@ -90,7 +90,7 @@ public abstract class ExecuteCommandBehaviorBase : AttachedToVisualTreeBehavior<
///
/// </summary>
/// <returns></returns>
protected bool ExecuteCommand()
protected virtual bool ExecuteCommand()
{
if (!IsEnabled)
{

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnDoubleTappedBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnDoubleTappedBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnDoubleTappedBehavior : ExecuteCommandBehaviorBase
var dispose = AssociatedObject?
.AddDisposableHandler(
Gestures.DoubleTappedEvent,
AssociatedObject_DoubleTapped,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnDoubleTapped,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnDoubleTappedBehavior : ExecuteCommandBehaviorBase
}
}
private void AssociatedObject_DoubleTapped(object? sender, RoutedEventArgs e)
private void OnDoubleTapped(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnDoubleTappedBehavior : ExecuteCommandBehaviorBase
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnGotFocusBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnGotFocusBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnGotFocusBehavior : ExecuteCommandBehaviorBase
var dispose = AssociatedObject?
.AddDisposableHandler(
InputElement.GotFocusEvent,
AssociatedObject_GotFocus,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnGotFocus,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnGotFocusBehavior : ExecuteCommandBehaviorBase
}
}
private void AssociatedObject_GotFocus(object? sender, RoutedEventArgs e)
private void OnGotFocus(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnGotFocusBehavior : ExecuteCommandBehaviorBase
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnHoldingBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnHoldingBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnHoldingBehavior : ExecuteCommandBehaviorBase
var dispose = AssociatedObject?
.AddDisposableHandler(
Gestures.HoldingEvent,
AssociatedObject_Holding,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnHolding,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnHoldingBehavior : ExecuteCommandBehaviorBase
}
}
private void AssociatedObject_Holding(object? sender, RoutedEventArgs e)
private void OnHolding(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnHoldingBehavior : ExecuteCommandBehaviorBase
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -0,0 +1,40 @@
using Avalonia.Input;
namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public abstract class ExecuteCommandOnKeyBehaviorBase : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
/// </summary>
public static readonly StyledProperty<Key?> KeyProperty =
AvaloniaProperty.Register<ExecuteCommandOnKeyBehaviorBase, Key?>(nameof(Key));
/// <summary>
///
/// </summary>
public static readonly StyledProperty<KeyGesture?> GestureProperty =
AvaloniaProperty.Register<ExecuteCommandOnKeyBehaviorBase, KeyGesture?>(nameof(Gesture));
/// <summary>
///
/// </summary>
public Key? Key
{
get => GetValue(KeyProperty);
set => SetValue(KeyProperty, value);
}
/// <summary>
///
/// </summary>
public KeyGesture? Gesture
{
get => GetValue(GestureProperty);
set => SetValue(GestureProperty, value);
}
}

Просмотреть файл

@ -7,38 +7,8 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnKeyDownBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnKeyDownBehavior : ExecuteCommandOnKeyBehaviorBase
{
/// <summary>
///
/// </summary>
public static readonly StyledProperty<Key?> KeyProperty =
AvaloniaProperty.Register<ExecuteCommandOnKeyDownBehavior, Key?>(nameof(Key));
/// <summary>
///
/// </summary>
public static readonly StyledProperty<KeyGesture?> GestureProperty =
AvaloniaProperty.Register<ExecuteCommandOnKeyDownBehavior, KeyGesture?>(nameof(Gesture));
/// <summary>
///
/// </summary>
public Key? Key
{
get => GetValue(KeyProperty);
set => SetValue(KeyProperty, value);
}
/// <summary>
///
/// </summary>
public KeyGesture? Gesture
{
get => GetValue(GestureProperty);
set => SetValue(GestureProperty, value);
}
/// <summary>
///
/// </summary>
@ -49,7 +19,7 @@ public class ExecuteCommandOnKeyDownBehavior : ExecuteCommandBehaviorBase
.AddDisposableHandler(
InputElement.KeyDownEvent,
OnKeyDown,
RoutingStrategies.Bubble);
EventRoutingStrategy);
if (dispose is not null)
{
@ -74,82 +44,7 @@ public class ExecuteCommandOnKeyDownBehavior : ExecuteCommandBehaviorBase
if (ExecuteCommand())
{
e.Handled = true;
}
}
}
/// <summary>
///
/// </summary>
public class ExecuteCommandOnKeyUpBehavior : ExecuteCommandBehaviorBase
{
/// <summary>
///
/// </summary>
public static readonly StyledProperty<Key?> KeyProperty =
AvaloniaProperty.Register<ExecuteCommandOnKeyDownBehavior, Key?>(nameof(Key));
/// <summary>
///
/// </summary>
public static readonly StyledProperty<KeyGesture?> GestureProperty =
AvaloniaProperty.Register<ExecuteCommandOnKeyDownBehavior, KeyGesture?>(nameof(Gesture));
/// <summary>
///
/// </summary>
public Key? Key
{
get => GetValue(KeyProperty);
set => SetValue(KeyProperty, value);
}
/// <summary>
///
/// </summary>
public KeyGesture? Gesture
{
get => GetValue(GestureProperty);
set => SetValue(GestureProperty, value);
}
/// <summary>
///
/// </summary>
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
.AddDisposableHandler(
InputElement.KeyUpEvent,
OnKeyUp,
RoutingStrategies.Bubble);
if (dispose is not null)
{
disposable.Add(dispose);
}
}
private void OnKeyUp(object? sender, KeyEventArgs e)
{
var haveKey = Key is not null && e.Key == Key;
var haveGesture = Gesture is not null && Gesture.Matches(e);
if (!haveKey && !haveGesture)
{
return;
}
if (e.Handled)
{
return;
}
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -0,0 +1,50 @@
using System.Reactive.Disposables;
using Avalonia.Input;
using Avalonia.Interactivity;
namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnKeyUpBehavior : ExecuteCommandOnKeyBehaviorBase
{
/// <summary>
///
/// </summary>
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
.AddDisposableHandler(
InputElement.KeyUpEvent,
OnKeyUp,
EventRoutingStrategy);
if (dispose is not null)
{
disposable.Add(dispose);
}
}
private void OnKeyUp(object? sender, KeyEventArgs e)
{
var haveKey = Key is not null && e.Key == Key;
var haveGesture = Gesture is not null && Gesture.Matches(e);
if (!haveKey && !haveGesture)
{
return;
}
if (e.Handled)
{
return;
}
if (ExecuteCommand())
{
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnLostFocusBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnLostFocusBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnLostFocusBehavior : ExecuteCommandBehaviorBase
var dispose = AssociatedObject?
.AddDisposableHandler(
InputElement.LostFocusEvent,
AssociatedObject_LostFocus,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnLostFocus,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnLostFocusBehavior : ExecuteCommandBehaviorBase
}
}
private void AssociatedObject_LostFocus(object? sender, RoutedEventArgs e)
private void OnLostFocus(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnLostFocusBehavior : ExecuteCommandBehaviorBase
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnPinchBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnPinchBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnPinchBehavior : ExecuteCommandBehaviorBase
var dispose = AssociatedObject?
.AddDisposableHandler(
Gestures.PinchEvent,
AssociatedObject_Pinch,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnPinch,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnPinchBehavior : ExecuteCommandBehaviorBase
}
}
private void AssociatedObject_Pinch(object? sender, RoutedEventArgs e)
private void OnPinch(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnPinchBehavior : ExecuteCommandBehaviorBase
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnPinchEndedBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnPinchEndedBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnPinchEndedBehavior : ExecuteCommandBehaviorBase
var dispose = AssociatedObject?
.AddDisposableHandler(
Gestures.PinchEndedEvent,
AssociatedObject_PinchEnded,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnPinchEnded,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnPinchEndedBehavior : ExecuteCommandBehaviorBase
}
}
private void AssociatedObject_PinchEnded(object? sender, RoutedEventArgs e)
private void OnPinchEnded(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnPinchEndedBehavior : ExecuteCommandBehaviorBase
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnPointerCaptureLostBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnPointerCaptureLostBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnPointerCaptureLostBehavior : ExecuteCommandBehavior
var dispose = AssociatedObject?
.AddDisposableHandler(
InputElement.PointerCaptureLostEvent,
AssociatedObject_PointerCaptureLost,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnPointerCaptureLost,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnPointerCaptureLostBehavior : ExecuteCommandBehavior
}
}
private void AssociatedObject_PointerCaptureLost(object? sender, RoutedEventArgs e)
private void OnPointerCaptureLost(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnPointerCaptureLostBehavior : ExecuteCommandBehavior
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnPointerEnteredBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnPointerEnteredBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnPointerEnteredBehavior : ExecuteCommandBehaviorBase
var dispose = AssociatedObject?
.AddDisposableHandler(
InputElement.PointerEnteredEvent,
AssociatedObject_PointerEntered,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnPointerEntered,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnPointerEnteredBehavior : ExecuteCommandBehaviorBase
}
}
private void AssociatedObject_PointerEntered(object? sender, RoutedEventArgs e)
private void OnPointerEntered(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnPointerEnteredBehavior : ExecuteCommandBehaviorBase
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnPointerExitedBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnPointerExitedBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnPointerExitedBehavior : ExecuteCommandBehaviorBase
var dispose = AssociatedObject?
.AddDisposableHandler(
InputElement.PointerExitedEvent,
AssociatedObject_PointerExited,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnPointerExited,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnPointerExitedBehavior : ExecuteCommandBehaviorBase
}
}
private void AssociatedObject_PointerExited(object? sender, RoutedEventArgs e)
private void OnPointerExited(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnPointerExitedBehavior : ExecuteCommandBehaviorBase
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnPointerMovedBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnPointerMovedBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnPointerMovedBehavior : ExecuteCommandBehaviorBase
var dispose = AssociatedObject?
.AddDisposableHandler(
InputElement.PointerMovedEvent,
AssociatedObject_PointerMoved,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnPointerMoved,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnPointerMovedBehavior : ExecuteCommandBehaviorBase
}
}
private void AssociatedObject_PointerMoved(object? sender, RoutedEventArgs e)
private void OnPointerMoved(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnPointerMovedBehavior : ExecuteCommandBehaviorBase
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnPointerPressedBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnPointerPressedBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnPointerPressedBehavior : ExecuteCommandBehaviorBase
var dispose = AssociatedObject?
.AddDisposableHandler(
InputElement.PointerPressedEvent,
AssociatedObject_PointerPressed,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnPointerPressed,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnPointerPressedBehavior : ExecuteCommandBehaviorBase
}
}
private void AssociatedObject_PointerPressed(object? sender, RoutedEventArgs e)
private void OnPointerPressed(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnPointerPressedBehavior : ExecuteCommandBehaviorBase
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnPointerReleasedBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnPointerReleasedBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnPointerReleasedBehavior : ExecuteCommandBehaviorBas
var dispose = AssociatedObject?
.AddDisposableHandler(
InputElement.PointerReleasedEvent,
AssociatedObject_PointerReleased,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnPointerReleased,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnPointerReleasedBehavior : ExecuteCommandBehaviorBas
}
}
private void AssociatedObject_PointerReleased(object? sender, RoutedEventArgs e)
private void OnPointerReleased(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnPointerReleasedBehavior : ExecuteCommandBehaviorBas
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnPointerTouchPadGestureMagnifyBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnPointerTouchPadGestureMagnifyBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnPointerTouchPadGestureMagnifyBehavior : ExecuteComm
var dispose = AssociatedObject?
.AddDisposableHandler(
Gestures.PointerTouchPadGestureMagnifyEvent,
AssociatedObject_PointerTouchPadGestureMagnify,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnPointerTouchPadGestureMagnify,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnPointerTouchPadGestureMagnifyBehavior : ExecuteComm
}
}
private void AssociatedObject_PointerTouchPadGestureMagnify(object? sender, RoutedEventArgs e)
private void OnPointerTouchPadGestureMagnify(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnPointerTouchPadGestureMagnifyBehavior : ExecuteComm
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnPointerTouchPadGestureRotateBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnPointerTouchPadGestureRotateBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnPointerTouchPadGestureRotateBehavior : ExecuteComma
var dispose = AssociatedObject?
.AddDisposableHandler(
Gestures.PointerTouchPadGestureRotateEvent,
AssociatedObject_PointerTouchPadGestureRotate,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnPointerTouchPadGestureRotate,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnPointerTouchPadGestureRotateBehavior : ExecuteComma
}
}
private void AssociatedObject_PointerTouchPadGestureRotate(object? sender, RoutedEventArgs e)
private void OnPointerTouchPadGestureRotate(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnPointerTouchPadGestureRotateBehavior : ExecuteComma
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnPointerTouchPadGestureSwipeBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnPointerTouchPadGestureSwipeBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnPointerTouchPadGestureSwipeBehavior : ExecuteComman
var dispose = AssociatedObject?
.AddDisposableHandler(
Gestures.PointerTouchPadGestureSwipeEvent,
AssociatedObject_PointerTouchPadGestureSwipe,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnPointerTouchPadGestureSwipe,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnPointerTouchPadGestureSwipeBehavior : ExecuteComman
}
}
private void AssociatedObject_PointerTouchPadGestureSwipe(object? sender, RoutedEventArgs e)
private void OnPointerTouchPadGestureSwipe(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnPointerTouchPadGestureSwipeBehavior : ExecuteComman
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnPointerWheelChangedBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnPointerWheelChangedBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnPointerWheelChangedBehavior : ExecuteCommandBehavio
var dispose = AssociatedObject?
.AddDisposableHandler(
InputElement.PointerWheelChangedEvent,
AssociatedObject_PointerWheelChanged,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnPointerWheelChanged,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnPointerWheelChangedBehavior : ExecuteCommandBehavio
}
}
private void AssociatedObject_PointerWheelChanged(object? sender, RoutedEventArgs e)
private void OnPointerWheelChanged(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnPointerWheelChangedBehavior : ExecuteCommandBehavio
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnPullGestureBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnPullGestureBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnPullGestureBehavior : ExecuteCommandBehaviorBase
var dispose = AssociatedObject?
.AddDisposableHandler(
Gestures.PullGestureEvent,
AssociatedObject_PullGesture,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnPullGesture,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnPullGestureBehavior : ExecuteCommandBehaviorBase
}
}
private void AssociatedObject_PullGesture(object? sender, RoutedEventArgs e)
private void OnPullGesture(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnPullGestureBehavior : ExecuteCommandBehaviorBase
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnPullGestureEndedBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnPullGestureEndedBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnPullGestureEndedBehavior : ExecuteCommandBehaviorBa
var dispose = AssociatedObject?
.AddDisposableHandler(
Gestures.PullGestureEndedEvent,
AssociatedObject_PullGestureEnded,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnPullGestureEnded,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnPullGestureEndedBehavior : ExecuteCommandBehaviorBa
}
}
private void AssociatedObject_PullGestureEnded(object? sender, RoutedEventArgs e)
private void OnPullGestureEnded(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnPullGestureEndedBehavior : ExecuteCommandBehaviorBa
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnRightTappedBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnRightTappedBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnRightTappedBehavior : ExecuteCommandBehaviorBase
var dispose = AssociatedObject?
.AddDisposableHandler(
Gestures.RightTappedEvent,
AssociatedObject_RightTapped,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnRightTapped,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnRightTappedBehavior : ExecuteCommandBehaviorBase
}
}
private void AssociatedObject_RightTapped(object? sender, RoutedEventArgs e)
private void OnRightTapped(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnRightTappedBehavior : ExecuteCommandBehaviorBase
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnScrollGestureBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnScrollGestureBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnScrollGestureBehavior : ExecuteCommandBehaviorBase
var dispose = AssociatedObject?
.AddDisposableHandler(
Gestures.ScrollGestureEvent,
AssociatedObject_ScrollGesture,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnScrollGesture,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnScrollGestureBehavior : ExecuteCommandBehaviorBase
}
}
private void AssociatedObject_ScrollGesture(object? sender, RoutedEventArgs e)
private void OnScrollGesture(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnScrollGestureBehavior : ExecuteCommandBehaviorBase
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnScrollGestureEndedBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnScrollGestureEndedBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnScrollGestureEndedBehavior : ExecuteCommandBehavior
var dispose = AssociatedObject?
.AddDisposableHandler(
Gestures.ScrollGestureEndedEvent,
AssociatedObject_ScrollGestureEnded,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnScrollGestureEnded,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnScrollGestureEndedBehavior : ExecuteCommandBehavior
}
}
private void AssociatedObject_ScrollGestureEnded(object? sender, RoutedEventArgs e)
private void OnScrollGestureEnded(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnScrollGestureEndedBehavior : ExecuteCommandBehavior
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnScrollGestureInertiaStartingBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnScrollGestureInertiaStartingBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnScrollGestureInertiaStartingBehavior : ExecuteComma
var dispose = AssociatedObject?
.AddDisposableHandler(
Gestures.ScrollGestureInertiaStartingEvent,
AssociatedObject_ScrollGestureInertiaStarting,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnScrollGestureInertiaStarting,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnScrollGestureInertiaStartingBehavior : ExecuteComma
}
}
private void AssociatedObject_ScrollGestureInertiaStarting(object? sender, RoutedEventArgs e)
private void OnScrollGestureInertiaStarting(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnScrollGestureInertiaStartingBehavior : ExecuteComma
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnTappedBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnTappedBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnTappedBehavior : ExecuteCommandBehaviorBase
var dispose = AssociatedObject?
.AddDisposableHandler(
Gestures.TappedEvent,
AssociatedObject_Tapped,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnTapped,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnTappedBehavior : ExecuteCommandBehaviorBase
}
}
private void AssociatedObject_Tapped(object? sender, RoutedEventArgs e)
private void OnTapped(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnTappedBehavior : ExecuteCommandBehaviorBase
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnTextInputBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnTextInputBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnTextInputBehavior : ExecuteCommandBehaviorBase
var dispose = AssociatedObject?
.AddDisposableHandler(
InputElement.TextInputEvent,
AssociatedObject_TextInput,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnTextInput,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnTextInputBehavior : ExecuteCommandBehaviorBase
}
}
private void AssociatedObject_TextInput(object? sender, RoutedEventArgs e)
private void OnTextInput(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnTextInputBehavior : ExecuteCommandBehaviorBase
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class ExecuteCommandOnTextInputMethodClientRequestedBehavior : ExecuteCommandBehaviorBase
public class ExecuteCommandOnTextInputMethodClientRequestedBehavior : ExecuteCommandRoutedEventBehaviorBase
{
/// <summary>
///
@ -18,8 +18,8 @@ public class ExecuteCommandOnTextInputMethodClientRequestedBehavior : ExecuteCom
var dispose = AssociatedObject?
.AddDisposableHandler(
InputElement.TextInputMethodClientRequestedEvent,
AssociatedObject_TextInputMethodClientRequested,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
OnTextInputMethodClientRequested,
EventRoutingStrategy);
if (dispose is not null)
{
@ -27,7 +27,7 @@ public class ExecuteCommandOnTextInputMethodClientRequestedBehavior : ExecuteCom
}
}
private void AssociatedObject_TextInputMethodClientRequested(object? sender, RoutedEventArgs e)
private void OnTextInputMethodClientRequested(object? sender, RoutedEventArgs e)
{
if (e.Handled)
{
@ -36,7 +36,7 @@ public class ExecuteCommandOnTextInputMethodClientRequestedBehavior : ExecuteCom
if (ExecuteCommand())
{
e.Handled = true;
e.Handled = MarkAsHandled;
}
}
}

Просмотреть файл

@ -0,0 +1,29 @@
using Avalonia.Interactivity;
namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public abstract class ExecuteCommandRoutedEventBehaviorBase : ExecuteCommandBehaviorBase
{
/// <summary>
///
/// </summary>
public static readonly StyledProperty<RoutingStrategies> EventRoutingStrategyProperty =
AvaloniaProperty.Register<ExecuteCommandRoutedEventBehaviorBase, RoutingStrategies>(nameof(EventRoutingStrategy), RoutingStrategies.Bubble);
/// <summary>
///
/// </summary>
public RoutingStrategies EventRoutingStrategy
{
get => GetValue(EventRoutingStrategyProperty);
set => SetValue(EventRoutingStrategyProperty, value);
}
/// <summary>
///
/// </summary>
public bool MarkAsHandled { get; set; } = true;
}

Просмотреть файл

@ -0,0 +1,73 @@
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Threading;
namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public abstract class FocusBehaviorBase : AttachedToVisualTreeBehavior<Control>
{
/// <summary>
///
/// </summary>
public static readonly StyledProperty<bool> IsEnabledProperty =
AvaloniaProperty.Register<FocusBehaviorBase, bool>(nameof(IsEnabled), true);
/// <summary>
///
/// </summary>
public static readonly StyledProperty<NavigationMethod> NavigationMethodProperty =
AvaloniaProperty.Register<FocusBehaviorBase, NavigationMethod>(nameof(NavigationMethod));
/// <summary>
///
/// </summary>
public static readonly StyledProperty<KeyModifiers> KeyModifiersProperty =
AvaloniaProperty.Register<FocusBehaviorBase, KeyModifiers>(nameof(KeyModifiers));
/// <summary>
///
/// </summary>
public bool IsEnabled
{
get => GetValue(IsEnabledProperty);
set => SetValue(IsEnabledProperty, value);
}
/// <summary>
///
/// </summary>
public NavigationMethod NavigationMethod
{
get => GetValue(NavigationMethodProperty);
set => SetValue(NavigationMethodProperty, value);
}
/// <summary>
///
/// </summary>
public KeyModifiers KeyModifiers
{
get => GetValue(KeyModifiersProperty);
set => SetValue(KeyModifiersProperty, value);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected virtual bool Focus()
{
if (!IsEnabled)
{
return false;
}
Dispatcher.UIThread.Post(() => AssociatedObject?.Focus(NavigationMethod, KeyModifiers));
return true;
}
}

Просмотреть файл

@ -1,38 +1,18 @@
using System.Reactive.Disposables;
using Avalonia.Controls;
using Avalonia.Threading;
namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class FocusOnAttachedBehavior : AttachedToVisualTreeBehavior<Control>
public class FocusOnAttachedBehavior : FocusBehaviorBase
{
/// <summary>
///
/// </summary>
public static readonly StyledProperty<bool> IsEnabledProperty =
AvaloniaProperty.Register<FocusOnAttachedBehavior, bool>(nameof(IsEnabled), true);
/// <summary>
///
/// </summary>
public bool IsEnabled
{
get => GetValue(IsEnabledProperty);
set => SetValue(IsEnabledProperty, value);
}
/// <summary>
///
/// </summary>
/// <param name="disposables"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposables)
{
if (IsEnabled)
{
Dispatcher.UIThread.Post(() => AssociatedObject?.Focus());
}
Focus();
}
}

Просмотреть файл

@ -8,29 +8,14 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public class KeyDownTrigger : DisposingTrigger
public class KeyDownTrigger : RoutedEventTriggerBase
{
/// <summary>
///
/// </summary>
public static readonly StyledProperty<RoutingStrategies> EventRoutingStrategyProperty =
AvaloniaProperty.Register<KeyDownTrigger, RoutingStrategies>(nameof(EventRoutingStrategy));
/// <summary>
///
/// </summary>
public static readonly StyledProperty<Key> KeyProperty =
AvaloniaProperty.Register<KeyDownTrigger, Key>(nameof(Key));
/// <summary>
///
/// </summary>
public RoutingStrategies EventRoutingStrategy
{
get => GetValue(EventRoutingStrategyProperty);
set => SetValue(EventRoutingStrategyProperty, value);
}
/// <summary>
///
/// </summary>

Просмотреть файл

@ -0,0 +1,24 @@
using Avalonia.Interactivity;
namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
///
/// </summary>
public abstract class RoutedEventTriggerBase : DisposingTrigger
{
/// <summary>
///
/// </summary>
public static readonly StyledProperty<RoutingStrategies> EventRoutingStrategyProperty =
AvaloniaProperty.Register<RoutedEventTriggerBase, RoutingStrategies>(nameof(EventRoutingStrategy));
/// <summary>
///
/// </summary>
public RoutingStrategies EventRoutingStrategy
{
get => GetValue(EventRoutingStrategyProperty);
set => SetValue(EventRoutingStrategyProperty, value);
}
}

Просмотреть файл

@ -32,7 +32,7 @@ public class SelectListBoxItemOnPointerMovedBehavior : Behavior<Control>
{
if (AssociatedObject is {Parent: ListBoxItem item})
{
item.IsSelected = true;
item.SetCurrentValue(ListBoxItem.IsSelectedProperty, true);
Dispatcher.UIThread.Post(() => item.Focus());
}
}

Просмотреть файл

@ -1,4 +1,5 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Threading;
namespace Avalonia.Xaml.Interactions.Custom;
@ -20,6 +21,12 @@ public abstract class ShowBehaviorBase : AttachedToVisualTreeBehavior<Control>
public static readonly StyledProperty<Control?> TargetControlProperty =
AvaloniaProperty.Register<ShowBehaviorBase, Control?>(nameof(TargetControl));
/// <summary>
///
/// </summary>
public static readonly StyledProperty<RoutingStrategies> EventRoutingStrategyProperty =
AvaloniaProperty.Register<ShowBehaviorBase, RoutingStrategies>(nameof(EventRoutingStrategy), RoutingStrategies.Bubble);
/// <summary>
///
/// </summary>
@ -39,6 +46,15 @@ public abstract class ShowBehaviorBase : AttachedToVisualTreeBehavior<Control>
set => SetValue(TargetControlProperty, value);
}
/// <summary>
///
/// </summary>
public RoutingStrategies EventRoutingStrategy
{
get => GetValue(EventRoutingStrategyProperty);
set => SetValue(EventRoutingStrategyProperty, value);
}
/// <summary>
///
/// </summary>

Просмотреть файл

@ -19,7 +19,7 @@ public class ShowOnDoubleTappedBehavior : ShowBehaviorBase
.AddDisposableHandler(
Gestures.DoubleTappedEvent,
AssociatedObject_DoubleTapped,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
EventRoutingStrategy);
if (dispose is not null)
{

Просмотреть файл

@ -49,7 +49,7 @@ public class ShowOnKeyDownBehavior : ShowBehaviorBase
.AddDisposableHandler(
InputElement.KeyDownEvent,
AssociatedObject_KeyDown,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
EventRoutingStrategy);
if (dispose is not null)
{

Просмотреть файл

@ -19,7 +19,7 @@ public class ShowOnTappedBehavior : ShowBehaviorBase
.AddDisposableHandler(
Gestures.TappedEvent,
AssociatedObject_Tapped,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
EventRoutingStrategy);
if (dispose is not null)
{