Skip to content

Instantly share code, notes, and snippets.

@clausjoergensen
Created July 18, 2011 11:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clausjoergensen/1089190 to your computer and use it in GitHub Desktop.
Save clausjoergensen/1089190 to your computer and use it in GitHub Desktop.
A generic LongListCollection for use with the Silverlight Toolkit's LongListSelector
public class LongListCollection<T, TKey> : List<LongListItem<T, TKey>>
{
public LongListCollection()
{
}
public LongListCollection(IEnumerable<T> items, Func<T, TKey> keySelector)
{
if (items == null)
throw new ArgumentException("items");
var groups = new Dictionary<TKey, LongListItem<T, TKey>>();
foreach (var item in items)
{
var key = keySelector(item);
if (groups.ContainsKey(key) == false)
groups.Add(key, new LongListItem<T, TKey>(key));
groups[key].Add(item);
}
this.AddRange(groups.Values);
}
}
public class LongListItem<T, TKey> : List<T>
{
public LongListItem()
{
}
public LongListItem(TKey key)
{
this.Key = key;
}
public TKey Key
{
get;
set;
}
public bool HasItems
{
get
{
return Count > 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment