This commit is contained in:
TheXamlGuy
2024-05-05 09:42:21 +01:00
parent 53efbb13c5
commit 287aa3131b
4 changed files with 111 additions and 86 deletions
@@ -0,0 +1,34 @@
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();
}
}