Collection of controls for WinUI 2, WinUI 3, and Uno Platform developers. Simplifies and demonstrates common developer tasks building experiences for Windows with .NET.
[Feature] TokenizingTextBox - Make TokenItemAdding event to be invoked even if the adding object is not a string to allow pre-check and cancellation #529
So when the user selects the already added item from SuggestedItemsSource, only QuerySubmitted event is invoked and I cannot prevent the duplicate item adding.
Thus, allowing TokenItemAdding to be invoked even if the data parameter is not a string would allow me to prevent duplicate items adding by checking the adding object and cancelling the event.
if (TokenItemAdding != null)
{
TokenItemAddingEventArgs tiaea;
if (data is string str)
{
tiaea = new TokenItemAddingEventArgs(str);
}
else
{
tiaea = new TokenItemAddingEventArgs(null) { Item = data };
}
await TokenItemAdding.InvokeAsync(this, tiaea);
...
}
Alternatives
Create new TokenizingTextBoxQuerySubmittedEventArgs class and either remove sealed from AutoSuggestBoxQuerySubmittedEventArgs and derive from it like this:
public class TokenizingTextBoxQuerySubmittedEventArgs : AutoSuggestBoxQuerySubmittedEventArgs
{
public bool Cancel { get; set; }
}
Or just create a similar class with additional Cancel property:
public class TokenizingTextBoxQuerySubmittedEventArgs
{
public object ChosenSuggestion { get; }
public string QueryText { get; }
public bool Cancel { get; set; } = false;
}
Describe the problem
Currently,
TokenizingTextBox
does not fireTokenItemAdding
event when thedata
parameter inAddTokenAsync(object data)
is not astring
.So when the user selects the already added item from
SuggestedItemsSource
, onlyQuerySubmitted
event is invoked and I cannot prevent the duplicate item adding.Thus, allowing
TokenItemAdding
to be invoked even if thedata
parameter is not astring
would allow me to prevent duplicate items adding by checking the adding object and cancelling the event.Describe the solution
Modify
AddTokenAsync(object data)
Alternatives
Create new
TokenizingTextBoxQuerySubmittedEventArgs
class and either removesealed
fromAutoSuggestBoxQuerySubmittedEventArgs
and derive from it like this:Or just create a similar class with additional
Cancel
property:Create a new
TokenizingTextBoxQuerySubmitted
event inTokenizingTextBox.Events.cs
RaiseQuerySubmitted
AutoSuggestBox_QuerySubmitted
Additional info
No response
Help us help you
None