Merge pull request #358 from gehongyan/breadcrubmitem-commandparameter

feat: Breadcrumb and its item may support CommandParameter/Binding
This commit is contained in:
Dong Bin
2024-08-21 20:19:33 +08:00
committed by GitHub
2 changed files with 25 additions and 1 deletions

View File

@@ -35,6 +35,17 @@ public class Breadcrumb: ItemsControl
set => SetValue(CommandBindingProperty, value);
}
public static readonly StyledProperty<IBinding?> CommandParameterBindingProperty = AvaloniaProperty.Register<Breadcrumb, IBinding?>(
nameof(CommandParameterBinding));
[AssignBinding]
[InheritDataTypeFromItems(nameof(ItemsSource))]
public IBinding? CommandParameterBinding
{
get => GetValue(CommandParameterBindingProperty);
set => SetValue(CommandParameterBindingProperty, value);
}
public static readonly StyledProperty<object?> SeparatorProperty = AvaloniaProperty.Register<Breadcrumb, object?>(
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;

View File

@@ -39,6 +39,15 @@ public class BreadcrumbItem: ContentControl
set => SetValue(CommandProperty, value);
}
public static readonly StyledProperty<object?> CommandParameterProperty = AvaloniaProperty.Register<BreadcrumbItem, object?>(
nameof(CommandParameter));
public object? CommandParameter
{
get => GetValue(CommandParameterProperty);
set => SetValue(CommandParameterProperty, value);
}
public static readonly StyledProperty<IDataTemplate?> IconTemplateProperty = AvaloniaProperty.Register<BreadcrumbItem, IDataTemplate?>(
nameof(IconTemplate));
@@ -62,7 +71,7 @@ public class BreadcrumbItem: ContentControl
base.OnPointerPressed(e);
if (!IsReadOnly)
{
Command?.Execute(null);
Command?.Execute(CommandParameter);
}
}
}