This repository was archived by the owner on Aug 27, 2020. It is now read-only.
  
  
  - 
                Notifications
    
You must be signed in to change notification settings  - Fork 37
 
GroupedObservableCollection
        Mark Smith edited this page Aug 29, 2016 
        ·
        1 revision
      
    The GroupedObservableCollection<TKey,TValue> is an observable collection of TValue items which supports grouping. You can use this collection as the direct data source for a ListView with grouping turned on.
- 
Key: the read-only value the items are grouped by. - 
HasItems: true/false whether the collection has any items 
The key must be passed to one of the two constructors and is considered a read-only value.
In this code sample, we take a set of un-ordered items, group them by the first letter and then
turn that into an ObservableCollection. Our final GroupedPeople will be of type ObservableCollection<GroupedObservableCollection<string,Person>>.
using XamarinUniversity.Infrastructure;
using using XamarinUniversity.Collections;
...
 
public class MyViewModel : SimpleViewModel
{
   public IList<GroupedObservableCollection<string,Person>> GroupedPeople { get; set; }
   public MyViewModel()
   {
       var allPeople = GetPeople(); // un-grouped list.
       GroupedPeople = allPeople.GroupBy(p => p.Name[0].ToString(), p => p)
                           .ToGroupedObservable ()    // IEnumerable<GroupedObservable..>
                           .ToObservableCollection(); // ObservableCollection<GroupedObservable..>>
   }
}