问题
I'm using an ItemControl to display a list of strings (like a suggestion-list). My problem is that it sometimes duplicates one entry..
I've tried to disable virtualization without success...
this is my xaml-code:
<ItemsControl ItemsSource="{Binding ResultList}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical" IsVirtualizing="False" IsContainerVirtualizable="False" VirtualizationMode="Standard"></VirtualizingStackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button>
<Button.Template>
<ControlTemplate TargetType="Button">
<TextBlock Text="{Binding DisplayName}"></TextBlock>
</ControlTemplate>
</Button.Template>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
as you can see there are 3 strings shown but I only have 2 in my binding-ResultList...(Ergebnisse 2 is bound to the ResultList.Count)
ResultList is of type ObservableCollection().
回答1:
I finally found a solution for that problem.
These duplicate items are only shown when I put my listbox in a popup (to simulate a suggestion-field).
The only thing I had to do was adding this line of code after I changed the entries of ResultList to Refresh the list.
CollectionViewSource.GetDefaultView(field.ResultList).Refresh();
来源:https://stackoverflow.com/questions/47773236/wpf-itemscontrol-shows-duplicate-entries