feat: add command

This commit is contained in:
rabbitism
2023-06-23 12:54:27 +08:00
parent b69f118063
commit f606667a3f

View File

@@ -1,4 +1,4 @@
using System.Security.Cryptography.X509Certificates;
using System.Windows.Input;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
@@ -66,6 +66,24 @@ public class NavigationMenuItem: HeaderedSelectingItemsControl
private set => SetAndRaise(LevelProperty, ref _level, value);
}
public static readonly StyledProperty<ICommand> CommandProperty = AvaloniaProperty.Register<NavigationMenuItem, ICommand>(
nameof(Command));
public ICommand Command
{
get => GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}
public static readonly StyledProperty<object?> CommandParameterProperty = AvaloniaProperty.Register<NavigationMenuItem, object?>(
nameof(CommandParameter));
public object? CommandParameter
{
get => GetValue(CommandParameterProperty);
set => SetValue(CommandParameterProperty, value);
}
static NavigationMenuItem()
{
IsClosedProperty.Changed.AddClassHandler<NavigationMenuItem>((o, e) => o.OnIsClosedChanged(e));
@@ -139,7 +157,7 @@ public class NavigationMenuItem: HeaderedSelectingItemsControl
this.PseudoClasses.Set(PC_Collapsed, _isCollapsed);
}
e.Handled = true;
Command?.Execute(CommandParameter);
}
internal void SetSelection(NavigationMenuItem? source, bool selected, bool propagateToParent = false)