I wish to highlight the columns on a WPF datagrid as the mouse moves. Some of the problems I face are:
- Getting the coordinates of columns to test for when the mouse is over them
- Changing the background color of a column
Any help will be much appreciated.
How about updating the style for the DataGridCell and defining an “IsMouseOver” trigger in it? Something like this:
EDIT:
Below is a solution that: 1) highlights the currently hovered cell, 2) highlights the entire row, and 3) highlights the entire column. I just coded this up quickly and haven’t tested it thoroughly so you might encounter some issues. But anyway, this should give you an idea on how they can be done.
My solution for highlighting the entire column involves the use of two attached properties that were being assigned to the DataGridCell when the mouse is over it. Just check it out and see if it works for you.
XAML:
DataGridBehavior class: