WPF Itemscontrol显示重复的条目 [英] WPF Itemscontrol shows duplicate entries

查看:63
本文介绍了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显示重复的条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆