Apply fix to sample to show proper way to use TokenizingTextBox Binding to ItemsSource

Avoids bug #4248
This commit is contained in:
michael-hawker 2021-09-14 16:34:58 -07:00
Родитель 6fd3327228
Коммит f992af412c
2 изменённых файлов: 10 добавлений и 4 удалений

Просмотреть файл

@ -90,7 +90,9 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
private AdvancedCollectionView _acv;
private AdvancedCollectionView _acvEmail;
private ObservableCollection<SampleEmailDataType> _selectedEmails;
public ObservableCollection<SampleDataType> SelectedTokens { get; set; }
public ObservableCollection<SampleEmailDataType> SelectedEmails { get; set; }
public TokenizingTextBoxPage()
{
@ -112,7 +114,10 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
public void OnXamlRendered(FrameworkElement control)
{
_selectedEmails = new ObservableCollection<SampleEmailDataType>();
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;

Просмотреть файл

@ -37,6 +37,7 @@
</TextBlock>
<controls:TokenizingTextBox
x:Name="TokenBox"
ItemsSource="{Binding SelectedTokens}"
PlaceholderText="Add Actions"
QueryIcon="{ui:SymbolIconSource Symbol=Setting}"
MaxHeight="104"
@ -65,7 +66,7 @@
<Run>Current Edit: </Run>
<Run Text="{Binding Text, ElementName=TokenBox}"/>
</TextBlock>
<ItemsControl ItemsSource="{Binding ItemsSource, ElementName=TokenBox}"/>
<ItemsControl ItemsSource="{Binding SelectedTokens}"/>
</StackPanel>
<StackPanel Grid.Row="1">
@ -73,6 +74,7 @@
Margin="0,0,0,4"/>
<controls:TokenizingTextBox
x:Name="TokenBoxEmail"
ItemsSource="{Binding SelectedEmails}"
PlaceholderText="Select Names"
MaxHeight="104"
HorizontalAlignment="Stretch"