Displaying large sorted lists in WPF QUICKLY?

I am developing a program that should be able to display long (up to 500 items) lists of data that need to be resorted when their contents change.

Essentially, I have a viewmodel with an observable collection that contains classes with observable data bound to the gui, which is displayed in a ListView.

The data must be sorted, but the data may also change at any time, and the list needs to be resorted each time.

What is the best mechanism / metaphor for displaying and keeping the whole thing resorted without locking up the GUI? I have a solution using NotifyCollectionChangedEventArgs and some sorting functions, but its SLOW - I'm assuming it resorts and rebuilds the entire GUI each time a data element is changed.


Have a look at the CollectionView/CollectionViewSource classes. These classes sit 'between' your ObservableCollection and WPF's data binding logic in order to perform operations like sorting, filtering, etc.

I suspect that writing your own sorting functions off of NotifyCollectionChanged is the source of your performance issues; it depends on your precise implementation, but there probably are a flurry of CollectionChanged events being raised as you sort the list, which results in WPF re-binding the collection each iteration of your sort routine... which would be incredibly slow, as you described.

CollectionView and CollectionViewSource don't affect the source collection, just the view of the collection displayed on the UI, so you should see a significant speedup over what you are doing now. When Microsoft's DataGrid control was released, they had demos of it displaying and sorting millions of rows - and it's using precisely these classes to perform its sorts. You really shouldn't be seeing performance problems on 500 rows.

Finally, the difference between CollectionView and CollectionViewSource are where they are designed to be used; CollectionView is used when you are working in C#, CollectionViewSource when you're doing it from XAML. You may also want to have a look at this article for a quick overview of these classes.

Need Your Help

Passing variable from batch file to SSIS package

ssis batch-file

I have created a package which takes a variable from batch file and uses it for execution.

Return void messing up reference parameter value

java return pass-by-reference void

I wrote this code with the intention of chain being incremented each time recurse() is called. It does this, however (from what I saw with the debugger) each time recurse() reaches a return;, it

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.