VB.NET ListView / ListBox WPF中的已检查项

时间:2013-04-03 18:38:26

标签: wpf vb.net listview listbox

如何在listview(或listbox)中添加已选中(或未选中)的商品?

我搜索了很长时间,但我总是在Windows窗体上找到关于CheckedListBox对象和ListView.Checked属性的主题,这些属性似乎不存在于WPF中。

我成功地使用活动目录中的某些组填充列表,但我不知道如何通过简单的检查(或隐藏它们)来显示它们。

我是否需要导入一些参考文献?

我正在使用VB.NET和Visual Studio Express 2012。

1 个答案:

答案 0 :(得分:1)

您需要为ItemTemplate

定义ListBox
         <ListBox ItemsSource="{Binding}" SelectionMode="Extended">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <CheckBox IsChecked="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType=ListBoxItem}}"
                              Content="{Binding}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
相关问题