From 591d53cbd3e4238aca5d4cdb58398d4162c0b125 Mon Sep 17 00:00:00 2001 From: Gehongyan Date: Wed, 21 Aug 2024 13:47:29 +0800 Subject: [PATCH] feat: Breadcrumb and its item may support CommandParameter/Binding --- src/Ursa/Controls/Breadcrumb/Breadcrumb.cs | 15 +++++++++++++++ src/Ursa/Controls/Breadcrumb/BreadcrumbItem.cs | 11 ++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Ursa/Controls/Breadcrumb/Breadcrumb.cs b/src/Ursa/Controls/Breadcrumb/Breadcrumb.cs index 4818d40..c020dfe 100644 --- a/src/Ursa/Controls/Breadcrumb/Breadcrumb.cs +++ b/src/Ursa/Controls/Breadcrumb/Breadcrumb.cs @@ -35,6 +35,17 @@ public class Breadcrumb: ItemsControl set => SetValue(CommandBindingProperty, value); } + public static readonly StyledProperty CommandParameterBindingProperty = AvaloniaProperty.Register( + nameof(CommandParameterBinding)); + + [AssignBinding] + [InheritDataTypeFromItems(nameof(ItemsSource))] + public IBinding? CommandParameterBinding + { + get => GetValue(CommandParameterBindingProperty); + set => SetValue(CommandParameterBindingProperty, value); + } + public static readonly StyledProperty SeparatorProperty = AvaloniaProperty.Register( nameof(Separator)); @@ -112,6 +123,10 @@ public class Breadcrumb: ItemsControl { breadcrumbItem[!BreadcrumbItem.CommandProperty] = CommandBinding; } + if (!breadcrumbItem.IsSet(BreadcrumbItem.CommandParameterProperty) && CommandParameterBinding != null) + { + breadcrumbItem[!BreadcrumbItem.CommandParameterProperty] = CommandParameterBinding; + } if (!breadcrumbItem.IsSet(BreadcrumbItem.IconTemplateProperty) && IconTemplate != null) { breadcrumbItem.IconTemplate = IconTemplate; diff --git a/src/Ursa/Controls/Breadcrumb/BreadcrumbItem.cs b/src/Ursa/Controls/Breadcrumb/BreadcrumbItem.cs index ea8edae..ce87a47 100644 --- a/src/Ursa/Controls/Breadcrumb/BreadcrumbItem.cs +++ b/src/Ursa/Controls/Breadcrumb/BreadcrumbItem.cs @@ -39,6 +39,15 @@ public class BreadcrumbItem: ContentControl set => SetValue(CommandProperty, value); } + public static readonly StyledProperty CommandParameterProperty = AvaloniaProperty.Register( + nameof(CommandParameter)); + + public object? CommandParameter + { + get => GetValue(CommandParameterProperty); + set => SetValue(CommandParameterProperty, value); + } + public static readonly StyledProperty IconTemplateProperty = AvaloniaProperty.Register( nameof(IconTemplate)); @@ -62,7 +71,7 @@ public class BreadcrumbItem: ContentControl base.OnPointerPressed(e); if (!IsReadOnly) { - Command?.Execute(null); + Command?.Execute(CommandParameter); } } } \ No newline at end of file