Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 998
Victor Rodrigues Avatar asked Jan 26 '09 13:01

Victor Rodrigues


1 Answers

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

like image 115
Ray Booysen Avatar answered Oct 25 '22 01:10

Ray Booysen