2017-08-09 132 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使用另外提供通知時計數變化(物品添加/移除)