using System.Collections.Generic; using System.Globalization; using Microsoft.Phone.Globalization; namespace File360 { public class AlphaKeyGroup : List { /// /// The delegate that is used to get the key information. /// /// An object of type T /// The key value to use for this object public delegate string GetKeyDelegate(T item); /// /// The Key of this group. /// public string Key { get; private set; } /// /// Public constructor. /// /// The key for this group. public AlphaKeyGroup(string key) { Key = key; } /// /// Create a list of AlphaGroup with keys set by a SortedLocaleGrouping. /// /// The /// Theitems source for a LongListSelector private static List> CreateGroups(SortedLocaleGrouping slg) { List> list = new List>(); foreach (string key in slg.GroupDisplayNames) { list.Add(new AlphaKeyGroup(key)); } return list; } /// /// Create a list of AlphaGroup with keys set by a SortedLocaleGrouping. /// /// The items to place in the groups. /// The CultureInfo to group and sort by. /// A delegate to get the key from an item. /// Will sort the data if true. /// An items source for a LongListSelector public static List> CreateGroups(IEnumerable items, CultureInfo ci, GetKeyDelegate getKey, bool sort) { SortedLocaleGrouping slg = new SortedLocaleGrouping(ci); List> list = CreateGroups(slg); foreach (T item in items) { int index = 0; if (slg.SupportsPhonetics) { //check if your database has yomi string for item //if it does not, then do you want to generate Yomi or ask the user for this item. //index = slg.GetGroupIndex(getKey(Yomiof(item))); } else { index = slg.GetGroupIndex(getKey(item)); } if (index >= 0 && index < list.Count) { list[index].Add(item); } } if (sort) { foreach (AlphaKeyGroup group in list) { group.Sort((c0, c1) => { return ci.CompareInfo.Compare(getKey(c0), getKey(c1)); }); } } return list; } } }