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 _acv;
private AdvancedCollectionView _acvEmail; private AdvancedCollectionView _acvEmail;
private ObservableCollection<SampleEmailDataType> _selectedEmails; public ObservableCollection<SampleDataType> SelectedTokens { get; set; }
public ObservableCollection<SampleEmailDataType> SelectedEmails { get; set; }
public TokenizingTextBoxPage() public TokenizingTextBoxPage()
{ {
@ -112,7 +114,10 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
public void OnXamlRendered(FrameworkElement control) public void OnXamlRendered(FrameworkElement control)
{ {
_selectedEmails = new ObservableCollection<SampleEmailDataType>(); SelectedTokens = new();
SelectedEmails = new();
control.DataContext = this;
if (_ttb != null) if (_ttb != null)
{ {
@ -150,7 +155,6 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{ {
_ttbEmail = ttbEmail; _ttbEmail = ttbEmail;
_ttbEmail.ItemsSource = _selectedEmails;
_ttbEmail.ItemClick += EmailTokenItemClick; _ttbEmail.ItemClick += EmailTokenItemClick;
_ttbEmail.TokenItemAdding += EmailTokenItemAdding; _ttbEmail.TokenItemAdding += EmailTokenItemAdding;
_ttbEmail.TokenItemAdded += EmailTokenItemAdded; _ttbEmail.TokenItemAdded += EmailTokenItemAdded;

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

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