【发布时间】:2018-01-17 07:13:29
【问题描述】:
在 mypage.xaml 中,我检索到了 ObservableCollection(Of MyObject)。
为了自动填充我的数据网格MyDataGrid 的(几乎所有)列,我像这样以编程方式放置了一个绑定
Class myPage
Private _context As New MyData
Private Sub Page_Loaded(sender As Object, e As RoutedEventArgs)
_context.MySubObject.Load
dataGrid.ItemsSource = _context.MySubObject.Local
End Sub
End Class
我像这样将MyDataGrid 的2 列绑定到MySubObject 的2 个属性
<DataGridTextColumn Header="ID" Binding="{Binding Id}"/>
<DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
这很好用。
现在,我想绑定第三列。我的问题是,MySubOject 的第三个属性是AnotherObject 的 ObservableCollection。我想为显示的每个MySubObject 显示AnotherObject 的对象数,例如:
ID | Name | NumberofAnotherObjects
----------------------------------
1 | abc | 42
2 | def | 56
3 | xyz | 592
我的想法是删除现有绑定并为所有三个创建一个 LINQ 查询。但我不知道如何在 LINQ 中动态构建这个总和。请给我一个提示好吗?
谢谢!
【问题讨论】:
-
那么,是总和还是计数?如果计数:只需将列绑定到集合计数属性
"{Binding AnotherObjectsCollection.Count}" -
这正是我想要的。谢谢
标签: wpf vb.net linq xaml datagrid