TreeView collapses when SortDescription is added

Hi group.

I have a TreeView which DataContext is bound to a CollectionViewSource.

As I press a Button, I want to enable sorting on the TreeView, thus in the eventhandler I add a SortDescription like this:

myCollectionViewSource.SortDescriptions.Add(newSortDescription("Category",ListSortDirection.Ascending));

But as this happens the TreeView is collapsed. I want it to maintain it's state... maybe by forcing the expanded TreeViewItems (who are now collapsed) to be expanded again, if that's nessesary?

Any ideas?

Thanks.

[1206 byte] By [Biggo] at [2008-1-8]
# 1

Hi there,

The problem is that the Sort will move object in the collection (in the ICollectionView)... so what will happen is that when the treeview will receive the CollectionChanged event the treeview will collapse the items...

I guess what you will have to do is to do the expansion of the tree view items manually..

If you want post your code and I will help you do this...

Regards

MarlonGrech at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified