Sorting using Dependency Property

Hello,

I'm trying to use Dependency Properties to sort Gridview. I'm 90% done, I got a nasty problem. So now I'm not sure if my approach is correct.

I've seen the sample where the gridview is sorted when a gridview header is clicked (How to: Sort a GridView Column When a Header Is Clicked ). However, I don't like the way they're switching templates in code.

So:

1. I introduced an attached property SortDirectionProperty.

2. Introduced a ColumnHeaderContainerStyle in which I set the template for GridViewColumnHeader (GVCH). And use triggers that check the attached property SortDirectionProperty.

3. When the GridViewColumnHeader.Click is invoked I figure out the sortDirection and assign it to the GVCH attached property SortDirectionProperty.

It all works great!

Except...

When I set the sortDirectionProperty on (say the first column header) GVCH1 to Asc, I need to make sure that all the other GVCH.SortDirection are set to None.

But I cannot loop through all the GVCH belonging to a gridview!!! In fact I don't think there is a way for me to navigate to a GVCH given a gridview (I put another post about this issue in the morning, there are no assocs from gridview -> GridviewColumnHeader.)

Sorry for the looong post, but can someone please help.

Regards,

Houman

P.S. Here is the highlight of the code: