2
我有以下列表框及其項目。列表框項目數據模板綁定
<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; }
}
的MyListItems是類型MyListItem的收集和MyTreeControl是具有ID作爲依賴屬性的用戶控件。
現在,我想在加載時將每個MyListItem的ID屬性分配給MyTreeControl的ID屬性。
<controls:MyTreeControl x:Name="myTree" ID={<I want to bind to MyListItem.ID>}/>
如何做到這一點?