【发布时间】:2009-02-03 09:35:29
【问题描述】:
我有一个列表框,我想遍历我的 Foo 对象中的 Bars 集合。
<ListBox DataContext="{Binding Path=Foo.Bars}" >
<ListBox.Items>
<ListBoxItem>
<ContentControl DataContext="{Binding Path=.}" />
</ListBoxItem>
</ListBox.Items>
</ListBox>
这是我要使用的数据模板。
<DataTemplate DataType="{x:Type Bar}">
<Label Content="hello stackoverflow" />
</DataTemplate>
如果我窥探(--> 使用 Snoop 工具检查)我的应用程序,我注意到 Bars 的整个集合都绑定到 ContentControl,而不仅仅是 1。
如何正确绑定,以便对集合的迭代顺利进行?
【问题讨论】:
标签: wpf data-binding xaml listview