2017-08-09 66 views
0

在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}"/>

这工作正常。 现在,我想绑定第3列。我的问题是,MySubOject的第3个属性是AnotherObject的ObservableCollection。我想显示的AnotherObject对象的数量为所显示,像每个MySubObject

ID | Name | NumberofAnotherObjects 
---------------------------------- 
1 | abc | 42 
2 | def | 56  
3 | xyz | 592 

我的想法是删除现有的绑定和创建三个LINQ查询。但我不知道如何在LINQ中动态构建这个总和。你能给我一个提示吗?

谢谢!

+0

所以,它是总结或计数?如果计数:只需将列绑定到集合Count属性''{Binding AnotherObjectsCollection.Count}“' – ASh

+0

这正是我所期待的。谢谢 – bluefox

回答

1

集合已经Count属性可在结合

<DataGridTextColumn Header="NumberofAnotherObjects" 
        Binding="{Binding AnotherObjectsCollection.Count}"/> 

的ObservableCollection使用另外提供通知时计数变化(物品添加/移除)