I have the following lines:
"Line 1"
"String 2"
"String 3"
"String 15"
"Line 17"
I want the rows to be sorted as above. However, when I use SortDescription to sort my list, I get the following output:
"Line 1"
"String 15"
"Line 17"
"String 2"
"String 3"
I understand that there are algorithms for this, however, is there a way to do this with the built-in SortDescription functions?
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 is the name of the property property in my view model, which represents the column that I want to sort.
It seems that I have only two sorting options: Ascending and Descending. But the CollectionView sorting method is not the way I would like my rows to be sorted. Is there an easy way to solve this problem?
source share