tags:

views:

31

answers:

2

Sorrry guys, I'm stuck here.

I have a few grids, I also have CollectionViewSource objects associated with those grids.

Now, I'm trying to apply CollectionViewSource.SortDescriptions in ColumnHeaderClick method, and now I have to define almost the same method for each grid.

But the only thing I really need is to obtain in which Grid is happenning.

How to get that, I have no idea. Help me please.

VisualTreeHelper.GetParent didn't work.

A: 

I think, probably, the best thing would be to derive your own grid control, adding the common functionality that you want. as for finding the the column that was clicked, here is some source code....

protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
{
   base.OnPreviewMouseLeftButtonUp(e);
   if ( e.OriginalSource is GridViewColumnHeader)
   {
      GridViewColumn col = ((GridViewColumnHeader)e.OriginalSource).Column as GridViewColumn;
     DoStuffWithYourColumn( col );
   }
}

oh, and one thing, you really should use the custom sorter instead of sort descriptions--sort descriptions are REALLY slow. take a look at this article for more information on the subject.

Muad'Dib
A: 

Oh.. it's turned out that it's possible to change the SortDesriptions directly in

(((System.Windows.Controls.ListBox)(sender)).Items)

Ike