I have following linq snippet
Note -> This is Metro App, and ICollectionView does not work as expected for grouping/sorting.
ObservableCollection<int> ints = new ObservableCollection<int>();
ints.Add(3);
ints.Add(4);
ints.Add(5);
ints.Add(6);
ints.Add(3);
ints.Add(4);
ints.Add(1);
ints.Add(2);
var groupedInts = ints.GroupBy(i=>i).Select(i=> new {Key=i.Key, Count=i.Count()});
I want following
-
To subscribe to groupedInts or ObservableCollection corresponding to it (basically databinding from WPF/Metro UI to groupInts)
-
Any change in ints (original observablecollection) should be reflected by groupedInts (so that UI subscribing to groupInts/related ObservableCollection can show the changes).
In actual scenario, the data structure is slightly complex (6-7 properties), but the problem boils down to above described issue.
There’s two ways I can think of.
1st : Use Bindable Linq / Continuous Linq
2nd : Create a seperate CollectionView for the groupedInts. When the original collection changes, this should change along with it. Here’s a nice and neat tutorial
AngelWPFs idea of Notifying the LINQ property as changed is viable, too.