Skip to content

Commit 9a9bbfc

Browse files
committed
Fix Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead
1 parent 5248b6d commit 9a9bbfc

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/tokenizingtextbox/TokenizingTextBox.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ private void AddToken(string token)
186186
}
187187
}
188188

189+
private void AddToken()
190+
{
191+
var text = _textBox.Text;
192+
_textBox.Text = string.Empty;
193+
AddToken(text);
194+
}
195+
189196
private void OnASBLoaded(object sender, RoutedEventArgs e)
190197
{
191198
if (_textBox != null)
@@ -208,8 +215,7 @@ private void TextBox_LostKeyboardFocus(object sender, KeyboardFocusChangedEventA
208215
_textBox.GotKeyboardFocus += TextBox_GotKeyboardFocus;
209216
if (AddOnFocusLost)
210217
{
211-
AddToken(_textBox.Text);
212-
_textBox.Text = string.Empty;
218+
AddToken();
213219
}
214220
}
215221

@@ -231,8 +237,7 @@ private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
231237
case Key.Enter when AcceptsReturn && !isEmpty:
232238
case Key.Tab when AcceptsTab && !isEmpty:
233239
e.Handled = true;
234-
AddText(_textBox.Text);
235-
_textBox.Text = string.Empty;
240+
AddToken();
236241
break;
237242
}
238243
}

0 commit comments

Comments
 (0)