Skip to content

Commit b4fecf3

Browse files
committed
Accounting for negative MaxToken value
1 parent 9ee8b96 commit b4fecf3

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBox.Properties.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private static void OnMaxTokensChanged(DependencyObject d, DependencyPropertyCha
173173
var tokenCount = ttb.Items.Count;
174174
if (tokenCount > newMaxTokens)
175175
{
176-
int tokensToRemove = newMaxTokens - tokenCount;
176+
int tokensToRemove = tokenCount - Math.Max(newMaxTokens, 0);
177177
var tokensRemoved = 0;
178178

179179
// Start at the end, remove any extra tokens.

Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBox.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private void ItemsSource_PropertyChanged(DependencyObject sender, DependencyProp
8181
if (MaxTokens.HasValue && _innerItemsSource.ItemsSource.Count > MaxTokens)
8282
{
8383
// Reduce down to the max as necessary.
84-
for (var i = _innerItemsSource.ItemsSource.Count; i > MaxTokens; --i)
84+
for (var i = _innerItemsSource.ItemsSource.Count - 1; i >= Math.Max(MaxTokens.Value, 0); --i)
8585
{
8686
_innerItemsSource.Remove(_innerItemsSource[i]);
8787
}
@@ -440,7 +440,7 @@ public async Task ClearAsync()
440440

441441
internal async Task AddTokenAsync(object data, bool? atEnd = null)
442442
{
443-
if (MaxTokens == 0)
443+
if (MaxTokens <= 0)
444444
{
445445
// No tokens for you
446446
return;

0 commit comments

Comments
 (0)