简体   繁体   English

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

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

People use frequently something like:人们经常使用类似的东西:

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

But I would like to use, instead of labels, a control, like this:但是我想使用一个控件而不是标签,如下所示:

<ListBox ItemsSource="{Binding ElementName=thisControl, Path=ListIndexes}">
<ListBox.ItemTemplate>
<DataTemplate>
<local:Index Item="**{Binding}**"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

My doubt is what to put into this Binding to include the whole item from the collection.我的疑问是将什么放入此 Binding 以包含集合中的整个项目。

The syntax for this is:其语法是:

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

This will tell the data binding functions to bind the entire datacontext for each ListBox Item to the Item property in your Index control这将告诉数据绑定函数将每个 ListBox Item 的整个数据上下文绑定到 Index 控件中的 Item 属性

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

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