TagInput 增加 CleanLostFocus 用于失去焦点后清空TextBox数据
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
<u:TagInput
|
||||
Margin="20"
|
||||
AllowDuplicates="False"
|
||||
CleanLostFocus="true"
|
||||
Separator="-"
|
||||
Tags="{Binding DistinctTags}" />
|
||||
<ListBox ItemsSource="{Binding DistinctTags}" />
|
||||
|
||||
@@ -50,6 +50,7 @@ public class TagInput : TemplatedControl
|
||||
{
|
||||
_textBox = new TextBox();
|
||||
_textBox.AddHandler(KeyDownEvent, OnTextBoxKeyDown, RoutingStrategies.Tunnel);
|
||||
_textBox.AddHandler(LostFocusEvent, OnTextBox_LostFocus, RoutingStrategies.Bubble);
|
||||
Items = new AvaloniaList<object>
|
||||
{
|
||||
_textBox
|
||||
@@ -57,6 +58,14 @@ public class TagInput : TemplatedControl
|
||||
Tags = new ObservableCollection<string>();
|
||||
}
|
||||
|
||||
private void OnTextBox_LostFocus(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if(CleanLostFocus)
|
||||
{
|
||||
_textBox.Text = "";
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<ControlTheme> InputThemeProperty =
|
||||
AvaloniaProperty.Register<TagInput, ControlTheme>(
|
||||
nameof(InputTheme));
|
||||
@@ -86,6 +95,16 @@ public class TagInput : TemplatedControl
|
||||
set => SetValue(SeparatorProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<bool> CleanLostFocusProperty = AvaloniaProperty.Register<TagInput, bool>(
|
||||
nameof(CleanLostFocus), defaultValue: false);
|
||||
|
||||
public bool CleanLostFocus
|
||||
{
|
||||
get => GetValue(CleanLostFocusProperty);
|
||||
set => SetValue(CleanLostFocusProperty, value);
|
||||
}
|
||||
|
||||
|
||||
public static readonly StyledProperty<bool> AllowDuplicatesProperty = AvaloniaProperty.Register<TagInput, bool>(
|
||||
nameof(AllowDuplicates), defaultValue: true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user