From f992af412cca7e90ef631cccfb5e91863371dfe2 Mon Sep 17 00:00:00 2001 From: michael-hawker <24302614+michael-hawker@users.noreply.github.com> Date: Tue, 14 Sep 2021 16:34:58 -0700 Subject: [PATCH] Apply fix to sample to show proper way to use TokenizingTextBox Binding to ItemsSource Avoids bug #4248 --- .../TokenizingTextBox/TokenizingTextBoxPage.xaml.cs | 10 +++++++--- .../TokenizingTextBox/TokenizingTextBoxXaml.bind | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxPage.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxPage.xaml.cs index 9e8909f66..990c4bcbe 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxPage.xaml.cs +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxPage.xaml.cs @@ -90,7 +90,9 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages private AdvancedCollectionView _acv; private AdvancedCollectionView _acvEmail; - private ObservableCollection _selectedEmails; + public ObservableCollection SelectedTokens { get; set; } + + public ObservableCollection SelectedEmails { get; set; } public TokenizingTextBoxPage() { @@ -112,7 +114,10 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages public void OnXamlRendered(FrameworkElement control) { - _selectedEmails = new ObservableCollection(); + SelectedTokens = new(); + SelectedEmails = new(); + + control.DataContext = this; if (_ttb != null) { @@ -150,7 +155,6 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages { _ttbEmail = ttbEmail; - _ttbEmail.ItemsSource = _selectedEmails; _ttbEmail.ItemClick += EmailTokenItemClick; _ttbEmail.TokenItemAdding += EmailTokenItemAdding; _ttbEmail.TokenItemAdded += EmailTokenItemAdded; diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxXaml.bind index fca7b60e1..5be567b09 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxXaml.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxXaml.bind @@ -37,6 +37,7 @@ Current Edit: - + @@ -73,6 +74,7 @@ Margin="0,0,0,4"/>