Files
Toolkit2/Toolkit.UI.Avalonia/AttachedEventTriggerBehaviour.cs
T
TheXamlGuy c0c1a82846 Codemaid
2024-05-24 08:21:50 +01:00

33 lines
937 B
C#

using Avalonia;
using Avalonia.Interactivity;
using Avalonia.Xaml.Interactivity;
namespace Toolkit.UI.Avalonia;
public class AttachedEventTriggerBehaviour : Trigger
{
public static readonly StyledProperty<RoutedEvent> RoutedEventProperty =
AvaloniaProperty.Register<AttachedEventTriggerBehaviour, RoutedEvent>(nameof(RoutedEvent));
public RoutedEvent RoutedEvent
{
get => GetValue(RoutedEventProperty);
set => SetValue(RoutedEventProperty, value);
}
protected override void OnAttached()
{
if (RoutedEvent is not null)
{
if (AssociatedObject is Interactive interactive)
{
interactive.AddHandler(RoutedEvent, (object sender, RoutedEventArgs args) =>
{
Interaction.ExecuteActions(AssociatedObject, Actions, null);
});
}
}
base.OnAttached();
}
}