Created
July 18, 2011 11:03
-
-
Save clausjoergensen/1089190 to your computer and use it in GitHub Desktop.
A generic LongListCollection for use with the Silverlight Toolkit's LongListSelector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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