views:

671

answers:

1

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.

+7  A: 

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

Ray Booysen