I am using Visual Studio 2012 for Windows 7. I need to know why the following style for the selected Grid line does not work for background and foreground colors, but works fine for other properties like BorderBrush and BorderThickness etc.? Although I see how they change when the mouse is over grids.
<Style x:Key="gridRowStyle" TargetType="{x:Type DataGridRow}"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="PeachPuff"/> <Setter Property="Foreground" Value="BlueViolet"/> </Trigger> <Trigger Property="IsSelected" Value="True"> <Setter Property="Background" Value="PeachPuff"/> <Setter Property="Foreground" Value="BlueViolet"/> <Setter Property="BorderBrush" Value="BlueViolet" /> <Setter Property="BorderThickness" Value="2" /> </Trigger> </Style.Triggers> </Style>
This is how I use the grid.
<DataGrid RowStyle="{StaticResource gridRowStyle}">
I emphasize that I know the “why” and not the solution to the problem, since I already have a solution to the problem if I use the grid cell style instead of the row, for example:
<Style x:Key="gridCellStyle" TargetType="{x:Type DataGridCell}"> <Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="Background" Value="PeachPuff"/> <Setter Property="Foreground" Value="BlueViolet"/> </Trigger> </Style.Triggers> </Style>
source share