From f606667a3f4d1c3c1a744f9945eadc9f380829ff Mon Sep 17 00:00:00 2001 From: rabbitism Date: Fri, 23 Jun 2023 12:54:27 +0800 Subject: [PATCH] feat: add command --- .../Controls/Navigation/NavigationMenuItem.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Ursa/Controls/Navigation/NavigationMenuItem.cs b/src/Ursa/Controls/Navigation/NavigationMenuItem.cs index 11067d1..dfc2963 100644 --- a/src/Ursa/Controls/Navigation/NavigationMenuItem.cs +++ b/src/Ursa/Controls/Navigation/NavigationMenuItem.cs @@ -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 CommandProperty = AvaloniaProperty.Register( + nameof(Command)); + + public ICommand Command + { + get => GetValue(CommandProperty); + set => SetValue(CommandProperty, value); + } + + public static readonly StyledProperty CommandParameterProperty = AvaloniaProperty.Register( + nameof(CommandParameter)); + + public object? CommandParameter + { + get => GetValue(CommandParameterProperty); + set => SetValue(CommandParameterProperty, value); + } + static NavigationMenuItem() { IsClosedProperty.Changed.AddClassHandler((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)