0

I am allowing the users to sort items shown by an ItemsControl using something similar to

var listCollectionView = CollectionViewSource.GetDefaultView(myItemsControl.ItemsSource);
listCollectionView.CustomSort = mySortComparer;
// Alternative, same Problem: 
// listCollectionView.SortDescriptions.Add(new SortDescription(myProperty)); 

The ItemTemplate for my collection is a little complicated and creating all the item representations requires a significant amount of time. I've found, using the profiler, that each sort re-creates every item in the ItemsControl, instead of using the old items and just moving them.

Is there a way to prevent this?

Jens
  • 25,229
  • 9
  • 75
  • 117

1 Answers1

1

Try using VirtualizingStackPanel as your ItemsControl's items panel if you aren't already. And also set VirtualizingStackPanel.VirtualizationMode attached property to Recycling on the ItemsControl.

vadim
  • 176
  • 6
  • This works as a workaround, thanks! I am still interested in another way though, since virtualization and touch-based, smooth scrolling are hard to do together prior to .NET 4.5. – Jens Apr 02 '14 at 12:18