From 1f6faa5ef7b9e36c8f75c16a2fde8e97038031b3 Mon Sep 17 00:00:00 2001 From: Slobodan Mumovic Date: Sun, 6 Aug 2023 13:43:23 +0200 Subject: [PATCH] Initial changes to introduce the new property and feature #4917 --- .../TokenizingTextBox.Properties.cs | 20 +++++++++++++++++++ .../TokenizingTextBoxItem.AutoSuggestBox.cs | 8 ++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBox.Properties.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBox.Properties.cs index 00a826cf243..fb8b1c17afe 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBox.Properties.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBox.Properties.cs @@ -116,6 +116,16 @@ private static void TextPropertyChanged(DependencyObject d, DependencyPropertyCh } } + /// + /// Identifies the property. + /// + public static readonly DependencyProperty KeepTextAfterQuerySubmittedProperty = DependencyProperty.Register( + nameof(KeepTextAfterQuerySubmitted), + typeof(bool), + typeof(TokenizingTextBox), + new PropertyMetadata(false)); + + /// /// Identifies the property. /// @@ -282,6 +292,16 @@ public string Text set => SetValue(TextProperty, value); } + /// + /// Gets or sets a value indicating whether the control should keep or clear the text + /// after the query is submitted. Default is false (to clear the text). + /// + public bool KeepTextAfterQuerySubmitted + { + get => (bool)GetValue(KeepTextAfterQuerySubmittedProperty); + set => SetValue(KeepTextAfterQuerySubmittedProperty, value); + } + /// /// Gets or sets the items source for token suggestions. /// diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBoxItem.AutoSuggestBox.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBoxItem.AutoSuggestBox.cs index 6b58b24bd1b..7f0fbfdb94b 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBoxItem.AutoSuggestBox.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBoxItem.AutoSuggestBox.cs @@ -153,8 +153,12 @@ private async void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSugg if (chosenItem != null) { await Owner.AddTokenAsync(chosenItem); // TODO: Need to pass index? - sender.Text = string.Empty; - Owner.Text = string.Empty; + if (!Owner.KeepTextAfterQuerySubmitted) + { + sender.Text = string.Empty; + Owner.Text = string.Empty; + } + sender.Focus(FocusState.Programmatic); } }