4

我的 WPF 应用程序使用XMLDataProvider它的数据。XML 文件有一个

<RELEASEDATE>dd/mm/yyyy</RELEASEDATE>

对于列出的每个项目。我正在使用 a 对应用程序中的数据进行排序

Listbox1.Items.SortDescriptions.Add(new SortDescription("RELEASEDATE", ListSortDirection.Descending));

结果不是预期的,因为日期被视为字符串。

最优雅的方法是什么?我可以以某种方式转换为内联日期吗?

4

1 回答 1

2

您必须实现自己的 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();

查看类似问题

于 2012-07-11T06:18:05.517 回答