<分区>
我有以下字符串:
“字符串 1”
“字符串 2”
“字符串 3”
“字符串 15”
“字符串 17”
我希望字符串按上述方式排序。但是,当我使用 SortDescription 对我的列表进行排序时,我得到以下输出:
“字符串 1”
“字符串 15”
“字符串 17”
“字符串 2”
“字符串 3”
我知道有一些算法可以实现这一点,但是有没有办法使用 SortDescription 的内置功能来实现这一点?
private void SortCol(string sortBy, ListSortDirection direction)
{
ICollectionView dataView =
CollectionViewSource.GetDefaultView(ListView.ItemsSource);
dataView.SortDescriptions.Clear();
SortDescription sd = new SortDescription(sortBy, direction);
dataView.SortDescriptions.Add(sd);
dataView.Refresh();
}
sortby 是我的 View 模型中表示我要排序的列的属性的属性名称。
似乎我仅有的两个排序选项是升序和降序。但是它对 CollectionView 进行排序的方式并不是我希望对字符串进行排序的方式。有解决这个问题的简单方法吗?