WPF Itemscontrol显示重复的条目

编程入门 行业动态 更新时间:2024-10-28 21:17:29
本文介绍了WPF Itemscontrol显示重复的条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用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显示重复的条目

本文发布于:2023-11-12 03:05:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580329.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条目   WPF   Itemscontrol

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!