繁体   English   中英

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

[英]Viewmodel has a list of items and each item has another list of items

我有一个带有以下itemsource的数据网格

ItemsSource="{Binding Path=MyItems, Mode=OneWay}"

在每个项目内都有一个名为“ MySubItems”的集合,我想在组合框中显示它们。但是,不知何故我无法到达它们...

ItemsSource="{Binding MySubItems,Source={StaticResource MyItemsModel}}"

我该如何实施? 谢谢 !

您可以使用点表示法来访问子属性:

ItemsSource="{Binding Path=MyItems.MySubItems, Mode=OneWay}"

但是,由于您尝试访问子对象的属性,所以我认为最简单的方法是将网格绑定到选定的value属性,然后将组合框绑定到该属性:

<ComboBox ItemsSource="{Binding SelectedItem.SubItems}"
          SelectedItem="{Binding SelectedComboItem}"
          IsSynchronizedWithCurrentItem="True"/>

DataGrid绑定:

<DataGrid ItemsSource="{Binding Path=MyItems, Mode=OneWay}"
          SelectedItem="{Binding SelectedItem, Mode=TwoWay}">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM