C# Windows phone longListSelector组(按月份和年份)
我有下面的分组课C# Windows phone longListSelector组(按月份和年份),c#,.net,windows-phone-8,longlistselector,C#,.net,Windows Phone 8,Longlistselector,我有下面的分组课 public class StringKeyGroup<T> : ObservableCollection<T> { public delegate string GetKeyDelegate(T item); public string Key { get; private set; } public StringKeyGroup(string key) { Key = key; } pu
public class StringKeyGroup<T> : ObservableCollection<T>
{
public delegate string GetKeyDelegate(T item);
public string Key { get; private set; }
public StringKeyGroup(string key)
{
Key = key;
}
public static ObservableCollection<StringKeyGroup<T>> CreateGroups(IEnumerable<T> items, CultureInfo ci, GetKeyDelegate getKey, bool sort)
{
var list = new ObservableCollection<StringKeyGroup<T>>();
foreach (var item in items)
{
var itemKey = getKey(item).ToLower();
var itemGroup = list.FirstOrDefault(li => li.Key == itemKey);
var itemGroupIndex = itemGroup != null ? list.IndexOf(itemGroup) : -1;
if (itemGroupIndex == -1)
{
list.Add(new StringKeyGroup<T>(itemKey));
itemGroupIndex = list.Count - 1;
}
if (itemGroupIndex >= 0 && itemGroupIndex < list.Count)
{
list[itemGroupIndex].Add(item);
}
}
if (sort)
{
string[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
foreach (var group in list)
{
//group.ToList().Sort((c0, c1) => ci.CompareInfo.Compare(getKey(c0), getKey(c1)));
}
}
return list;
}
}
问题是,月份看起来是这样的:
2013年12月、2013年6月、2013年1月
我想要像这样的数据
2013年1月、2013年6月、2013年12月等。
这取决于月份,然后是年份
从老到晚。
我一直在找,但什么也没找到,
请帮忙。我解决了这个问题。
而不是对字符串进行排序。
我用整数
公共int月
例如,我已经有了一个名为collection的数据列表
我使用了以下方法
var OrderedData=collection.OrderBy x=>x.Month.ToList
如果要对多个属性进行排序,可以执行以下操作
var OrderedData=collection.OrderBy x=>x.Month.thenby=>y.YourPropertyName.ToList 将数据按日期排序,而不是按组排序对不起,我没有按日期对数据进行排序,所以1月份优先
public class Data {
public string Name {get;set;}
public string Month {get;set;}
}