Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TokenizingTextBox] Keep text after a query is submitted #4922

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ private static void TextPropertyChanged(DependencyObject d, DependencyPropertyCh
}
}

/// <summary>
/// Identifies the <see cref="KeepTextAfterQuerySubmitted"/> property.
/// </summary>
public static readonly DependencyProperty KeepTextAfterQuerySubmittedProperty = DependencyProperty.Register(
nameof(KeepTextAfterQuerySubmitted),
typeof(bool),
typeof(TokenizingTextBox),
new PropertyMetadata(false));


/// <summary>
/// Identifies the <see cref="SuggestedItemsSource"/> property.
/// </summary>
Expand Down Expand Up @@ -282,6 +292,16 @@ public string Text
set => SetValue(TextProperty, value);
}

/// <summary>
/// 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).
/// </summary>
public bool KeepTextAfterQuerySubmitted
{
get => (bool)GetValue(KeepTextAfterQuerySubmittedProperty);
set => SetValue(KeepTextAfterQuerySubmittedProperty, value);
}

/// <summary>
/// Gets or sets the items source for token suggestions.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down