feat: add remove command support.

This commit is contained in:
rabbitism
2024-03-26 02:56:14 +08:00
parent 6993cdd7ab
commit bc4262efc8
5 changed files with 133 additions and 24 deletions

View File

@@ -0,0 +1,36 @@
using System.Windows.Input;
using Avalonia;
using Avalonia.Controls;
namespace Ursa.Controls;
public class MultiComboBoxSelectedItemList: ItemsControl
{
public static readonly StyledProperty<ICommand?> RemoveCommandProperty = AvaloniaProperty.Register<MultiComboBoxSelectedItemList, ICommand?>(
nameof(RemoveCommand));
public ICommand? RemoveCommand
{
get => GetValue(RemoveCommandProperty);
set => SetValue(RemoveCommandProperty, value);
}
protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey)
{
return NeedsContainer<ClosableTag>(item, out recycleKey);
}
protected override Control CreateContainerForItemOverride(object? item, int index, object? recycleKey)
{
return new ClosableTag();
}
protected override void PrepareContainerForItemOverride(Control container, object? item, int index)
{
base.PrepareContainerForItemOverride(container, item, index);
if (container is ClosableTag tag)
{
tag.Command = RemoveCommand;
}
}
}