Here is my xaml:
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border x:Name="border" removed="Transparent"
BorderBrush="Transparent"
BorderThickness="1"
SnapsToDevicePixels="True">
<ContentPresenter Name="CellContent" SnapsToDevicePixels="True" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="DataGridRow" x:Key="Project">
<Style.Triggers >
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Green" />
<Setter Property="BorderBrush" Value="Green" />
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="DataGridRow" x:Key="Revision" BasedOn="{StaticResource Project}">
<Style.Triggers >
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Red" />
<Setter Property="BorderBrush" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
private void chPrj_Checked(object sender, RoutedEventArgs e)
{
var rws = (from item in Rows where item.projects.Contains((sender as CheckBox).Content.ToString()) select item);
grdFileList.SelectionMode = DataGridSelectionMode.Extended;
for (int i = 0; i < grdFileList.Items.Count; i++)
{
DataGridRow r = (DataGridRow) grdFileList.ItemContainerGenerator.ContainerFromIndex(i);
SubstationDataRow gridRow = (SubstationDataRow)grdFileList.Items[i];
if (gridRow.projects.Any(x => x == (sender as CheckBox).Content.ToString()))
{
grdFileList.SelectedItems.Add(grdFileList.Items[i]);
r.Style = (Style)this.Resources["Project"];
r.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
updateRevListBox();
}
}
}
The problem is:
I can get all the correct rows selected but, only the last row has the correct selection color. The other rows are selected but, they don't have the red or green background color as specified in the styles. Instead, they have the normal background color but, all the text in the row is selected. (That's how i can tell that all the correct rows are selected).
If I remove the styles, all the rows are correctly highlighted with the default selection color.
How can i get all of the selected rows to retain their custom selection color (red or green)?
I'm fairly new to WPF so, forgive for my ignorance. Any help would be greatly appreciated.