/// <summary> /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping. /// </summary> /// <param name="slg">The sorted group headers for the specified locale</param> /// <returns>The items source for a LongListSelector</returns> private static List <AlphaKeyGroup <T> > CreateGroups(SortedLocaleGrouping slg) { List <AlphaKeyGroup <T> > list = new List <AlphaKeyGroup <T> >(); foreach (string key in slg.GroupDisplayNames) { if (key == "...") { list.Add(new AlphaKeyGroup <T>(GlobeGroupKey)); } else { list.Add(new AlphaKeyGroup <T>(key)); } } return(list); }
/// <summary> /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping. /// </summary> /// <param name="items">The items to place in the groups.</param> /// <param name="ci">The CultureInfo to group and sort by.</param> /// <param name="getKey">A delegate to get the key from an item.</param> /// <param name="sort">Will sort the data if true.</param> /// <returns>An items source for a LongListSelector</returns> public static List <AlphaKeyGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci, GetKeyDelegate getKey, bool sort) { SortedLocaleGrouping slg = new SortedLocaleGrouping(ci); List <AlphaKeyGroup <T> > list = CreateGroups(slg); foreach (T item in items) { int index = slg.GetGroupIndex(getKey(item)); if (index >= 0 && index < list.Count) { list[index].Add(item); } } if (sort) { foreach (AlphaKeyGroup <T> group in list) { group.Sort((c0, c1) => { return(ci.CompareInfo.Compare(getKey(c0), getKey(c1))); }); } } return(list); }