Skip to content

Commit

Permalink
Create RoutedEventTriggerBaseOfT.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Jan 6, 2025
1 parent 6981c04 commit 2c9f0eb
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Reactive.Disposables;
using Avalonia.Interactivity;
using Avalonia.Xaml.Interactivity;

namespace Avalonia.Xaml.Interactions.Custom;

/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class RoutedEventTriggerBase<T> : RoutedEventTriggerBase where T : RoutedEventArgs
{
/// <summary>
///
/// </summary>
protected abstract RoutedEvent<T> RoutedEvent { get; }

/// <summary>
///
/// </summary>
/// <param name="disposables"></param>
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);
}
}

0 comments on commit 2c9f0eb

Please sign in to comment.