人们经常使用类似的东西:
<ListBox ItemsSource="{Binding ElementName=thisControl, Path=ListIndexes}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Label Content="{Binding Path=IndexName}"/>
<Label Content="{Binding Path=IndexValue}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
但我想使用控件而不是标签,如下所示:
<ListBox ItemsSource="{Binding ElementName=thisControl, Path=ListIndexes}">
<ListBox.ItemTemplate>
<DataTemplate>
<local:Index Item="**{Binding}**"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我的疑问是将什么放入此绑定(bind)以包含集合中的整个项目。
最佳答案
语法是:
<local:Index Item="{Binding}"/>
这将告诉数据绑定(bind)函数将每个 ListBox 项的整个数据上下文绑定(bind)到 Index 控件中的 Item 属性
关于c# - 如何将 ListBox 项绑定(bind)到用户控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/479737/