我有一个列表框,我想在我的Foo对象的Bar集合上进行迭代。
<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 上,而不仅仅是一个。
我该如何正确地绑定,以便对集合的迭代正常进行?