Style DataGrid cell to change foreground on MouseOver. How?

Aug 29, 2009 at 7:30 PM
Edited Aug 29, 2009 at 7:31 PM

Please advise on the most efficient way to change foreground colour on the whole column on mouse over that column...

I did some Silverlight and WPF is a bit new to me.

I need the most efficient CPU-wise solution for - on mouse enter over a particular column the whole column foreground should change and then on the mouse leave should reset to default colour.

My guess is that the best way is to do style for that column. What I've done is:

<Style x:Key="HoverColourCellStyle" TargetType="{x:Type tool:DataGridCell}" BasedOn="{StaticResource CenterAlignedCellStyle}"> 
    <EventSetter Event="MouseEnter" Handler="DataGridTextColumn_MouseEnter"/>

...the event handler works. Now I am not sure how to change style foreground according mouse enter/leave. I need CPU-efficient solution. What is the best - triggers? Bidning to a dependency property set in the mouse handlers or any other ways? (In Silverlight I would be looking for a Behavior or a visual state or both)...

Thank you

Nov 25, 2009 at 3:45 PM

In silverlight you can do it in the visual state wrapping DataGridCellPresenter into a contentControl.

Here is an example:

Nov 29, 2009 at 4:30 AM

thanks for your time. but the question was how to do it in WPF data grid in a most efficient way.