gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 10:59:25 25 4
gpt4 key购买 nike

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

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

在每个项目内都有一个名为“MySubItems”的集合,我想在组合框中显示它们..但不知何故我无法接触到它们......
ItemsSource="{Binding MySubItems,Source={StaticResource MyItemsModel}}"

我该如何实现?谢谢你 !

最佳答案

您可以使用点符号来访问子属性:

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

但是,由于您尝试访问子对象上的属性,我认为最简单的方法是将网格绑定(bind)到选定的值属性,然后将组合框绑定(bind)到该属性:
<ComboBox ItemsSource="{Binding SelectedItem.SubItems}"
SelectedItem="{Binding SelectedComboItem}"
IsSynchronizedWithCurrentItem="True"/>

数据网格绑定(bind):
<DataGrid ItemsSource="{Binding Path=MyItems, Mode=OneWay}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}">

关于c# - Viewmodel 有一个项目列表,每个项目都有另一个项目列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21095375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com