繁体   English   中英

如何将 ListBox 项绑定到用户控件?

[英]How to bind a ListBox item to a user control?

人们经常使用类似的东西:

<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>

我的疑问是将什么放入此 Binding 以包含集合中的整个项目。

其语法是:

<local:Index Item="{Binding}"/>

这将告诉数据绑定函数将每个 ListBox Item 的整个数据上下文绑定到 Index 控件中的 Item 属性

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM