How can I get DataGrid columns to show mouse hover and sort direction when CanUserSortColumns="False"?
I would like to provide my own implementation of sorting behaviour for the WPF DataGrid
as I am using a paged data model. My paging behaviour is working nicely, however the default sort behaviour for CanUserSortColumns="True"
causes the current page to sort, however I want to ca开发者_如何转开发pture this and sort it myself.
I figured I'd be able to provide sorting behaviour by listening to click events on the column headers and sorting appropriately, which works, however when CanUserSortColumns="False"
the column headers do not respond to mouse interaction any more and do not show the sort direction indicator.
I figured this would be the case, but I wish to know how I can restore the style without having to write a whole template that looks like the original.
Sorry, I can't remember whether or not it is possible to get the particular style which does the effects for the buttons or any control. They are default styles/templates for these controls and are probably not available. I do remember that templates are available only after shown unless explicitly set.
But, if your whole goal is to implement custom sorting, couldn't you just handle the Sorting
event instead? You even get a reference to the Column
that initiated the sorting and get the SortDirection
value prior to the sorting (null
-> Ascending
-> Descending
->). You could then sort your source as needed.
Can you leave CanUserSortColumns set to true, then handle the PreviewLeftMouseButton down, do your custom stuff, and set the event to handled so that it doesn't ever get into the default sort logic?
精彩评论