using System.Windows.Input; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Data; namespace ControlCatalog.Controls { public class HomeItemExpander : Expander, ISelectable { /// /// Defines the property. /// public static readonly StyledProperty CommandProperty = Button.CommandProperty.AddOwner(); /// /// Defines the property. /// public static readonly StyledProperty CommandParameterProperty = Button.CommandParameterProperty.AddOwner(); /// /// Defines the property. /// public static readonly StyledProperty CanExpandProperty = AvaloniaProperty.Register( nameof(CanExpand), defaultBindingMode: BindingMode.TwoWay); /// /// Defines the property. /// public static readonly DirectProperty IsEffectivelyExpandedProperty = AvaloniaProperty.RegisterDirect( nameof(IsEffectivelyExpanded), x => x.IsEffectivelyExpanded, (x, o) => x.IsEffectivelyExpanded = o, defaultBindingMode: BindingMode.TwoWay); /// /// Defines the property. /// public static readonly StyledProperty IsSelectedProperty = SelectingItemsControl.IsSelectedProperty.AddOwner(); /// /// Gets or sets an to be invoked when the button is clicked. /// public ICommand? Command { get => GetValue(CommandProperty); set => SetValue(CommandProperty, value); } /// /// Gets or sets a parameter to be passed to the . /// public object? CommandParameter { get => GetValue(CommandParameterProperty); set => SetValue(CommandParameterProperty, value); } /// /// Gets or sets a value indicating whether the /// content area is open and visible. /// public bool CanExpand { get => GetValue(CanExpandProperty); set => SetValue(CanExpandProperty, value); } /// /// Gets or sets the selection state of the item. /// public bool IsSelected { get => GetValue(IsSelectedProperty); set => SetValue(IsSelectedProperty, value); } /// /// Gets whether the is expanded /// public bool IsEffectivelyExpanded { get => field; private set => SetAndRaise(IsEffectivelyExpandedProperty, ref field, value); } protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) { base.OnPropertyChanged(change); if (change.Property == CanExpandProperty || change.Property == IsExpandedProperty) { IsEffectivelyExpanded = CanExpand && IsExpanded; } } } }