http://stackoverflow.com/questions/5895803/how-do-i-capture-click-events-on-a-datagrid-column-headers
The headers are just buttons. Like any button, you can register to the Click event to capture those clicks. Just set a style targeting DataGridColumnHeader and add a Click event handler. Then within the handler, you have access to the header directly via the sender . You could then get the Column associated with that header and other information associated with it. Then in the code: private void columnHeader_Click(object sender, RoutedEventArgs e){ var columnHeader = sender as DataGridColumnHeader; if (columnHeader != null) { // do stuff }} Looking further into the DataGrid , I noticed that there's a property. I think it would be a better idea to apply the style through this property instead. | | answered May 5 '11 at 10:51 | |
| |
EventSetter
before, very handy. I have a followup question, do you know if it's possible to get the style behaviour whenCanUserSortColumns="False"
so the headers respond to mouse hover and show the sort direction, or will I need to restyle these myself? –CanUserSortColumns
toFalse
otherwise the control will try to perform the sort false, however I want the nice "hover" affect when moving the cursor over the column header, and would like the "up/down" arrow indicating sort direction (though the latter is less important). Your help is very much appreciated. –