Merge pull request #690 from irihitech/tagInput
replace PathIcon with Button in ClosableTag
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="https://irihi.tech/ursa">
|
||||
<Design.PreviewWith>
|
||||
<u:ClosableTag Content="Closable Tag"/>
|
||||
</Design.PreviewWith>
|
||||
<ControlTheme x:Key="{x:Type u:TagInput}" TargetType="u:TagInput">
|
||||
<Setter Property="InputTheme" Value="{DynamicResource TagInputTextBoxTheme}" />
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
@@ -115,21 +118,23 @@
|
||||
<ControlTemplate TargetType="u:ClosableTag">
|
||||
<Border
|
||||
Margin="1"
|
||||
Padding="4,2"
|
||||
Padding="8,4,4,4"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
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"
|
||||
Background="Transparent"
|
||||
Data="{DynamicResource ClosableTagCloseIconGlyph}"
|
||||
Theme="{DynamicResource InnerIconButton}"
|
||||
DockPanel.Dock="Right"
|
||||
Foreground="{TemplateBinding Foreground}" />
|
||||
Width="12"
|
||||
Height="12"
|
||||
Margin="4,0,0,0"
|
||||
Foreground="{DynamicResource SemiColorText2}"
|
||||
Command="{TemplateBinding Command}"
|
||||
CommandParameter="{TemplateBinding}"
|
||||
Content="{StaticResource ClosableTagCloseIconGlyph}" />
|
||||
<ContentPresenter
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Content="{TemplateBinding Content}"
|
||||
@@ -141,5 +146,11 @@
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
<Style Selector="^ /template/ Button#PART_CloseButton:pointerover">
|
||||
<Setter Property="Foreground" Value="{DynamicResource SemiColorText1}" />
|
||||
</Style>
|
||||
<Style Selector="^ /template/ Button#PART_CloseButton:pressed">
|
||||
<Setter Property="Foreground" Value="{DynamicResource SemiColorText0}" />
|
||||
</Style>
|
||||
</ControlTheme>
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary>
|
||||
@@ -2,16 +2,14 @@ using System.Windows.Input;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Input;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
[TemplatePart(PART_CloseButton, typeof(PathIcon))]
|
||||
public class ClosableTag: ContentControl
|
||||
[TemplatePart(PART_CloseButton, typeof(Button))]
|
||||
public class ClosableTag : ContentControl
|
||||
{
|
||||
public const string PART_CloseButton = "PART_CloseButton";
|
||||
private PathIcon? _icon;
|
||||
|
||||
public static readonly StyledProperty<ICommand?> CommandProperty = AvaloniaProperty.Register<ClosableTag, ICommand?>(
|
||||
nameof(Command));
|
||||
|
||||
@@ -20,27 +18,4 @@ public class ClosableTag: ContentControl
|
||||
get => GetValue(CommandProperty);
|
||||
set => SetValue(CommandProperty, value);
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
if (_icon != null)
|
||||
{
|
||||
_icon.PointerPressed -= OnPointerPressed;
|
||||
}
|
||||
_icon = e.NameScope.Find<PathIcon>(PART_CloseButton);
|
||||
if (_icon != null)
|
||||
{
|
||||
_icon.PointerPressed += OnPointerPressed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnPointerPressed(object? sender, PointerPressedEventArgs args)
|
||||
{
|
||||
if (Command != null && Command.CanExecute(null))
|
||||
{
|
||||
Command.Execute(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user