diff --git a/demo/Ursa.Demo/Pages/TagInputDemo.axaml b/demo/Ursa.Demo/Pages/TagInputDemo.axaml index fc94f33..eb5dbfc 100644 --- a/demo/Ursa.Demo/Pages/TagInputDemo.axaml +++ b/demo/Ursa.Demo/Pages/TagInputDemo.axaml @@ -21,6 +21,7 @@ diff --git a/src/Ursa/Controls/TagInput/TagInput.cs b/src/Ursa/Controls/TagInput/TagInput.cs index 920d9ac..aa45ab4 100644 --- a/src/Ursa/Controls/TagInput/TagInput.cs +++ b/src/Ursa/Controls/TagInput/TagInput.cs @@ -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 { _textBox @@ -57,6 +58,14 @@ public class TagInput : TemplatedControl Tags = new ObservableCollection(); } + private void OnTextBox_LostFocus(object? sender, RoutedEventArgs e) + { + if(CleanLostFocus) + { + _textBox.Text = ""; + } + } + public static readonly StyledProperty InputThemeProperty = AvaloniaProperty.Register( nameof(InputTheme)); @@ -86,6 +95,16 @@ public class TagInput : TemplatedControl set => SetValue(SeparatorProperty, value); } + public static readonly StyledProperty CleanLostFocusProperty = AvaloniaProperty.Register( + nameof(CleanLostFocus), defaultValue: false); + + public bool CleanLostFocus + { + get => GetValue(CleanLostFocusProperty); + set => SetValue(CleanLostFocusProperty, value); + } + + public static readonly StyledProperty AllowDuplicatesProperty = AvaloniaProperty.Register( nameof(AllowDuplicates), defaultValue: true);