Override sorting in WPF DataGrid / ListCollectionView
I've overridden a ListCollectionView to lazy load only those items which are needed for display.
I'm using this ListCollectionView in a DataGrid to show and edit items.
This works nicely, just like it should.
My problem: I want the user to be able to sort the DataGrid by clicking on the header column. Since I lazy load the items only when I need them, the ListCollectionView does a bad job on 开发者_C百科sorting those items which has not been loaded yet.
One way to solve this would be to load all items, but I don't want to do that since this might be way too many items to load in a respectable time.
Instead I would like to get the notification and tell my (remote) data source to hand me the items pre-sorted instead.
Is there an easy way to intercept the sorting in either the DataGrid or (better) the ListCollectionView and do it myself, somehow?
If you need for a data virtualization, there is a special library for this on codeplex. All that you have to do is to implement the following method:
public IList<T> LoadRange(int startIndex, int count,
SortDescriptionCollection sortDescriptions, out int overallCount)
Inside this method you can call a WCF-service and return a sorted and truncated list. This library isn't easy to understand, but it works.
精彩评论