feat: replace PathIcon with Button.

This commit is contained in:
Zhang Dian
2025-06-02 02:12:24 +08:00
parent 7f160489ff
commit b81d6c69a7
2 changed files with 13 additions and 30 deletions

View File

@@ -3,15 +3,14 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
namespace Ursa.Controls;
[TemplatePart(PART_CloseButton, typeof(PathIcon))]
[TemplatePart(PART_CloseButton, typeof(Button))]
public class ClosableTag : ContentControl
{
public const string PART_CloseButton = "PART_CloseButton";
private PathIcon? _icon;
private Button? _closeButton;
public static readonly StyledProperty<ICommand?> CommandProperty = AvaloniaProperty.Register<ClosableTag, ICommand?>(
nameof(Command));
@@ -25,23 +24,6 @@ public class ClosableTag : ContentControl
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
if (_icon is not null)
{
_icon.PointerReleased -= OnPointerReleased;
}
_icon = e.NameScope.Find<PathIcon>(PART_CloseButton);
if (_icon is not null)
{
_icon.PointerReleased += OnPointerReleased;
}
}
private void OnPointerReleased(object? sender, PointerReleasedEventArgs args)
{
if (Command is not null && Command.CanExecute(null))
{
Command.Execute(this);
}
_closeButton = e.NameScope.Find<Button>(PART_CloseButton);
}
}