Setting an AlternatingRowBackground prevents the highlight from appearing while moving over a row.
Example to reproduce:
<DataGrid HorizontalAlignment="Left" Height="317" Margin="41,122,0,0" VerticalAlignment="Top" Width="732"
Name="grdData" AutoGenerateColumns="False" AlternationCount="2"
AlternatingRowBackground="#FF282828">
<DataGrid.Columns>
<DataGridTextColumn Header="test1" Binding="{Binding}"/>
</DataGrid.Columns>
</DataGrid>
I've managed to fix this, but the solution does require a workaround. I've modified the style for DataGridRow as this was setting the Background colour which meant AlternatingRowBackground could not be set from a DataGrid style. I'll create a pull request for this shortly.
For the AlternatingRowBackground to work though, it must be set from a style rather than directly on the DataGrid itself. I don't think there is another alternative. I found a few posts on stackoverflow about it and this seemed to be the only solution.
The style can be set as follows:
c#
<DataGrid ItemsSource="{Binding Path=Albums}"
Grid.Row="0"
AutoGenerateColumns="False">
<DataGrid.Style>
<Style TargetType="DataGrid" BasedOn="{StaticResource {x:Type DataGrid}}">
<Setter Property="AlternatingRowBackground" Value="#FF282828"/>
</Style>
</DataGrid.Style>
<DataGrid.Columns>
<DataGridTextColumn Header="Title" Binding="{Binding Title}" />
<DataGridTextColumn Header="Artist" Binding="{Binding Artist.Name}" />
<DataGridTextColumn Header="Genre" Binding="{Binding Genre.Name}" />
<DataGridTextColumn Header="Price" Binding="{Binding Price,StringFormat=c}" />
</DataGrid.Columns>
</DataGrid>
or you can create a style based on the DataGrid style adding the AlternatingRowBackground so you don't need to do this on every DataGrid.
Most helpful comment
I've managed to fix this, but the solution does require a workaround. I've modified the style for DataGridRow as this was setting the Background colour which meant AlternatingRowBackground could not be set from a DataGrid style. I'll create a pull request for this shortly.
For the AlternatingRowBackground to work though, it must be set from a style rather than directly on the DataGrid itself. I don't think there is another alternative. I found a few posts on stackoverflow about it and this seemed to be the only solution.
The style can be set as follows:
c# <DataGrid ItemsSource="{Binding Path=Albums}" Grid.Row="0" AutoGenerateColumns="False"> <DataGrid.Style> <Style TargetType="DataGrid" BasedOn="{StaticResource {x:Type DataGrid}}"> <Setter Property="AlternatingRowBackground" Value="#FF282828"/> </Style> </DataGrid.Style> <DataGrid.Columns> <DataGridTextColumn Header="Title" Binding="{Binding Title}" /> <DataGridTextColumn Header="Artist" Binding="{Binding Artist.Name}" /> <DataGridTextColumn Header="Genre" Binding="{Binding Genre.Name}" /> <DataGridTextColumn Header="Price" Binding="{Binding Price,StringFormat=c}" /> </DataGrid.Columns> </DataGrid>or you can create a style based on the DataGrid style adding the AlternatingRowBackground so you don't need to do this on every DataGrid.