Wednesday, January 14, 2009

Sorting a ListView in WPF

Sorting a ListView in WPF was really hard for me to figure out, but I found this solution in WPF Unleashed:


myListView.Items.SortDescriptions.Clear();
myListView.Items.SortDescriptions.Add(new SortDescription("AttributeName", ListSortDirection.Ascending));


This will keep the listview sorted even if it is bound to an ObservableCollection.

No comments:

Post a Comment