C# 如何将ListBox项绑定到用户控件?
人们经常使用以下东西:C# 如何将ListBox项绑定到用户控件?,c#,.net,wpf,wpf-controls,C#,.net,Wpf,Wpf Controls,人们经常使用以下东西: <ListBox ItemsSource="{Binding ElementName=thisControl, Path=ListIndexes}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <Label Content="{Binding Path=IndexName}"/> <Label Content="{Binding Path=Inde
<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>
我的疑问是在这个绑定中放入什么来包含集合中的整个项目。其语法是:
<local:Index Item="{Binding}"/>
这将告诉数据绑定函数将每个ListBox项的整个datacontext绑定到索引控件中的Item属性