Example #1
0
        /// <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)
        {
            var slg  = new SortedLocaleGrouping(ci);
            var list = CreateGroups(slg);

            foreach (var item in items)
            {
                var index = slg.GetGroupIndex(getKey(item));

                if (index >= 0 && index < list.Count)
                {
                    list[index].Add(item);
                }
            }

            if (!sort)
            {
                return(list);
            }
            foreach (var group in list)
            {
                @group.Sort((c0, c1) => ci.CompareInfo.Compare(getKey(c0), getKey(c1)));
            }

            return(list);
        }
Example #2
0
 /// <summary>
 /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
 /// </summary>
 /// <param name="slg">The </param>
 /// <returns>Theitems source for a LongListSelector</returns>
 private static List <AlphaKeyGroup <T> > CreateGroups(SortedLocaleGrouping slg)
 {
     return(slg.GroupDisplayNames.Select(key => new AlphaKeyGroup <T>(key)).ToList());
 }