From 2c9f0eb139dc4485070170856288e7f485935c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20S=CC=8Colte=CC=81s?= Date: Mon, 6 Jan 2025 13:52:35 +0100 Subject: [PATCH] Create RoutedEventTriggerBaseOfT.cs --- .../Core/RoutedEventTriggerBaseOfT.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/Avalonia.Xaml.Interactions.Custom/Core/RoutedEventTriggerBaseOfT.cs diff --git a/src/Avalonia.Xaml.Interactions.Custom/Core/RoutedEventTriggerBaseOfT.cs b/src/Avalonia.Xaml.Interactions.Custom/Core/RoutedEventTriggerBaseOfT.cs new file mode 100644 index 00000000..f7793cd4 --- /dev/null +++ b/src/Avalonia.Xaml.Interactions.Custom/Core/RoutedEventTriggerBaseOfT.cs @@ -0,0 +1,44 @@ +using System.Reactive.Disposables; +using Avalonia.Interactivity; +using Avalonia.Xaml.Interactivity; + +namespace Avalonia.Xaml.Interactions.Custom; + +/// +/// +/// +/// +public abstract class RoutedEventTriggerBase : RoutedEventTriggerBase where T : RoutedEventArgs +{ + /// + /// + /// + protected abstract RoutedEvent RoutedEvent { get; } + + /// + /// + /// + /// + protected override void OnAttached(CompositeDisposable disposables) + { + if (AssociatedObject is Interactive interactive) + { + var disposable = interactive.AddDisposableHandler( + RoutedEvent, + Handler, + EventRoutingStrategy); + disposables.Add(disposable); + } + } + + private void Handler(object? sender, T e) + { + if (!IsEnabled) + { + return; + } + + e.Handled = MarkAsHandled; + Interaction.ExecuteActions(AssociatedObject, Actions, e); + } +}