我的 WPF 应用程序使用XMLDataProvider
为其数据。 XML 文件有一个
<RELEASEDATE>dd/mm/yyyy</RELEASEDATE>
对于每个列出的项目。我正在使用 a 对应用程序中的数据进行排序
Listbox1.Items.SortDescriptions.Add(new SortDescription("RELEASEDATE", ListSortDirection.Descending));
结果不是预期的,因为日期被视为字符串。
解决这个问题最优雅的方法是什么?我可以以某种方式转换为内联日期吗?
你必须实现自己的 IComparer:
class DateTimeComparer : IComparer
{
public int Compare(object x, object y)
{
//To Do : Implement DataTime Comparering
}
}
现在将 IComparer 实现分配给集合的 ListCollectionView.CustomSort:
ListCollectionView view = new ListCollectionView(ListBox.Items);
view.CustomSort = new DateTimeComparer();
查看类似问题 http://social.msdn.microsoft.com/Forums/en/wpf/thread/44efe318-0246-4021-a193-8a20b95ae55e
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)