Have you tried wrapping your collection in a CollectionView using the
CollectionViewSource class, and binding to it?  Of the top of my head, you
should be able to enumerate the sort descriptors on the collection view to
see how it's sorted, and set the sort descriptors on the collection view to
set the sorting in the DataGrid.

Chris


On 6 March 2012 23:39, Greg Keogh <[email protected]> wrote:

> Last week I asked if anyone knew how to detect when a DataGrid is sorted
> so that you can remember the column and direction, so you can restore them
> when the app starts again. It turns out this can be done, but not in the
> way I described the problem.****
>
> ** **
>
> There is no event in the DataGrid, DataView, DataTable or other bindable
> collection I can find that will tell you when a sort has been performed.
> You have to:****
>
> ** **
>
> trap the grid’s 
> Sorting<http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.sorting.aspx>event
> ****
>
> identify the grid column (which might be a template) and its current
> direction (which is nullable)****
>
> sort the data source yourself****
>
> then set the column’s SortDirection (to set the column header arrow)****
>
> set e.Handled = true****
>
> ** **
>
> You get the column and direction in the event, so it’s your responsibility
> to add a bit of plumbing to load and save a change of sort at a suitable
> time. I’ve done all this, and although it’s not much total code, it took an
> irritating amount of time to get it dead-right. A lot of time was wasted
> searching through hundreds of utterly stupid, off-track or misleading web
> articles on the subject ... which I think is a growing problem these days
> as amount of ”noise” articles is clogging search engines and wasting search
> time looking for rare “real” answers and advice.****
>
> ** **
>
> Greg****
>
> _______________________________________________
> ozwpf mailing list
> [email protected]
> http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf
>
>
_______________________________________________
ozwpf mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf

Reply via email to