简体   繁体   English

Viewmodel有一个项目列表,每个项目都有另一个项目列表

[英]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.

相关问题 检查列表的项目是否具有另一个列表中包含的属性 - Checking if a list's item has a property contained in another list of items Xamarin Listview 仅添加 1 个项目我的列表上有 2 个项目 - Xamarin Listview only adding 1 item my List has 2 items on it 如何获得list1项,其中sublist1的任何项至少具有list2的一项? - How to get list1 items that any items of sublist1 at least has one item of list2? 如果列表项有另一个列表,则深度克隆 - Deep Clone If List Item Has Another List 将以ExpandoObject作为项目的动态列表求和 - Sum on a dynamic list that has ExpandoObject as items LINQ获取具有项目列表的唯一ID - LINQ to get unique id that has list of items 如何检查列表是否包含所有数组项? - How to check list has all array items? 静态列表中的项目 <Item> () - Items in static List<Item>() 是否有Linq操作从项目列表中检索特定项目,其中该项目具有应为唯一的属性的属性值? - Is there a Linq operation to retrieve specific items from a list of items where the item has a property value for a property which should be unique? 如何在列表中查找属性具有特定值或具有与此值的相关项的所有项? - How to find all items in a list where a property has a specific value or where there is a related item with this value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM