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

@@ -124,16 +124,17 @@
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="3">
<DockPanel LastChildFill="True">
<PathIcon
<Button
Name="{x:Static u:ClosableTag.PART_CloseButton}"
Theme="{StaticResource InnerPathIcon}"
Classes="Small"
Margin="4,0,0,0"
Background="Transparent"
Data="{DynamicResource ClosableTagCloseIconGlyph}"
Theme="{DynamicResource InnerIconButton}"
DockPanel.Dock="Right"
Width="12"
Height="12"
Margin="4,0,0,0"
Foreground="{DynamicResource SemiColorText2}"
Cursor="Hand" />
Command="{TemplateBinding Command}"
CommandParameter="{TemplateBinding}"
Content="{StaticResource ClosableTagCloseIconGlyph}" />
<ContentPresenter
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
@@ -145,10 +146,10 @@
</Border>
</ControlTemplate>
</Setter>
<Style Selector="^ /template/ PathIcon#PART_CloseButton:pointerover">
<Style Selector="^ /template/ Button#PART_CloseButton:pointerover">
<Setter Property="Foreground" Value="{DynamicResource SemiColorText1}" />
</Style>
<Style Selector="^ /template/ PathIcon#PART_CloseButton:pressed">
<Style Selector="^ /template/ Button#PART_CloseButton:pressed">
<Setter Property="Foreground" Value="{DynamicResource SemiColorText0}" />
</Style>
</ControlTheme>

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);
}
}