1

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I was using the result of a Linq query - a .ToList() fixed it immediately. I had no idea the underlying type of the ItemsSource mattered. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.