How can I define one global GridViewColumnHeader.Click handler for any ListView.GridViewColumnHeader in my project?
I mean is it possible to set a Style or a Template in app.xaml for TargetType=GridViewColumnHeader so any columnheader in any listview in the project would response to the method in app.xaml.cs?
Yes, with one caveat: You can create a Style that applies to all GridViewColumnHeaders, but you cannot set the Click event in it. However you can set the Command property which has almost exactly the same result:
Now it is only required to create the command, register a class handler, and write the code to handle it:
Note that if you manually set the GridViewColumnHeader’s Command property anywhere else in your application it will take precedence over the style. If this is a concern, you may want to instead catch tunneling PreviewMouseDown events at your Window and check each to see if it’s original source is a GridViewColumnHeader.