[英]Viewmodel has a list of items and each item has another list of items
I have a datagrid with the following itemsource 我有一个带有以下itemsource的数据网格
ItemsSource="{Binding Path=MyItems, Mode=OneWay}"
Inside each item there is a collection called "MySubItems" and I want to show them in a combobox.. But somehow I can't reach them... 在每个项目内都有一个名为“ MySubItems”的集合,我想在组合框中显示它们。但是,不知何故我无法到达它们...
ItemsSource="{Binding MySubItems,Source={StaticResource MyItemsModel}}"
How do I implement this? 我该如何实施? thank you !
谢谢 !
You can use dot notation to access sub properties: 您可以使用点表示法来访问子属性:
ItemsSource="{Binding Path=MyItems.MySubItems, Mode=OneWay}"
Since you're trying to access properties on a sub object, however, I think the easiest way is to bind the grid to a selected value property and then have the combo box bound to that: 但是,由于您尝试访问子对象的属性,所以我认为最简单的方法是将网格绑定到选定的value属性,然后将组合框绑定到该属性:
<ComboBox ItemsSource="{Binding SelectedItem.SubItems}"
SelectedItem="{Binding SelectedComboItem}"
IsSynchronizedWithCurrentItem="True"/>
DataGrid binding: DataGrid绑定:
<DataGrid ItemsSource="{Binding Path=MyItems, Mode=OneWay}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.