JustABill
JustABill

Reputation: 1559

WPF 4, ListView and ListCollectionView custom sorting

I'm trying to use a custom sort with a ListView, as described in this blog entry.

I'm doing

ListCollectionView view = (ListCollectionView)CollectionViewSource.GetDefaultView(TheList.ItemsSource);

as recommended there and in several other places, but for some reason I'm getting "Unable to cast object of type 'MS.Internal.Data.EnumerableCollectionView' to type 'System.Windows.Data.ListCollectionView'." (TheList is of type ListView).

What could be causing this?

Upvotes: 1

Views: 3677

Answers (1)

Igor Zevaka
Igor Zevaka

Reputation: 76500

Looks like the underlying type of the source collection - i.e. TheList.ItemsSource is not a List but perhaps IEnumerable. Here is an article with more info.

Quick solution - use List<Whatever> as ItemsSource for TheList.

Upvotes: 2

Related Questions