Reputation: 485
I have following list box and its item.
<ListBox Name="listBox" Width="Auto" Height="Auto" Margin="10" ItemsSource="{Binding MyListItems}">
<ItemsControl.ItemTemplate>
<DataTemplate x:Name="dt">
<controls:MyTreeControl x:Name="myTree"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
public class MyListItem
{
public string Name { get; set; }
public string ID { get; set; }
}
The MyListItems is collection of type MyListItem and MyTreeControl is a user control which has ID as a dependency property.
Now, I want to assign each MyListItem's ID property to MyTreeControl's ID property while it is loaded.
<controls:MyTreeControl x:Name="myTree" ID={<I want to bind to MyListItem.ID>}/>
How to do this?
Upvotes: 2
Views: 1773
Reputation: 62494
Since each item bound to the listBox is of type MyListItem
It should be simply
<controls:MyTreeControl
x:Name="myTree"
ID="{Binding ID}" />
Upvotes: 1