我正在使用ItemControl来显示字符串列表(如建议列表). 我的问题是,有时它会重复一个条目.
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...
这是我的xaml代码:
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>
您可以看到显示了3个字符串,但是我的binding-ResultList中只有2个字符串(Ergebnisse 2绑定到ResultList.Count)
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的类型为ObservableCollection().
ResultList is of type ObservableCollection().
推荐答案我终于找到了解决该问题的方法.
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).
我唯一要做的就是在更改ResultList的条目以刷新列表之后添加此行代码.
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();更多推荐
WPF Itemscontrol显示重复的条目
发布评论