列表框项数据模板绑定
我有以下列表框及其项目。
<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>}/>
如何做到这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于绑定到 listBox 的每个项目都是
MyListItem
类型,因此应该很简单Since each item bound to the listBox is of type
MyListItem
It should be simply