using Avalonia; using Avalonia.Metadata; using Avalonia.Xaml.Interactivity; using Toolkit.Foundation; namespace Toolkit.UI.Avalonia; public class ConditionAction : AvaloniaObject, IAction { public static readonly DirectProperty ActionsProperty = AvaloniaProperty.RegisterDirect(nameof(Actions), x => x.Actions); public static readonly StyledProperty ConditionProperty = AvaloniaProperty.Register(nameof(Condition)); private ActionCollection? actions; [Content] public ActionCollection Actions => actions ??= []; public ICondition Condition { get => GetValue(ConditionProperty); set => SetValue(ConditionProperty, value); } public object? Execute(object? sender, object? parameter) { bool? result = Condition?.Evaluate(); if (result is true) { Interaction.ExecuteActions(sender, Actions, parameter); } return true; } }