How to overwrite AlternatingRowBackground inside a DataGridRow template?

I am creating a DataGrid with rows with the AlternatingRowBackground property. However, the data in the rows must be changed, and this takes some time.

I am trying to make the background color of the lines light gray when they are initialized. Here is what I do in the RowTemplate:

<ControlTemplate.Triggers> <DataTrigger Binding="{Binding Initialized}" Value="False"> <Setter Property="Background" Value="LightGray"/> </DataTrigger> </ControlTemplate.Triggers> 

But this does not work for odd lines that still have the color specified in AlternatingRowBackground.

How to overwrite this so that all lines that were not initialized look light gray?

+3
c # wpf xaml datagrid
source share
1 answer

I had the same problem and worked further: Install AlternatingRowBackground in style but not in DataGrid.

  <Grid.Resources> <Style x:Key="dg" TargetType="DataGrid"> <Setter Property="AlternatingRowBackground" Value="Orange"/> <Setter Property="AutoGenerateColumns" Value="False"/> </Style> </Grid.Resources> <DataGrid ItemsSource="{Binding Source={StaticResource one}, Path=Persons}" Style="{StaticResource dg}"> <DataGrid.Columns> <DataGridTextColumn Width="*" Header="Name" Binding="{Binding Path=Name}"/> </DataGrid.Columns> <DataGrid.RowStyle> <Style TargetType="DataGridRow"> <Style.Triggers> <DataTrigger Binding="{Binding Mature}" Value="True"> <Setter Property="Background" Value="LightGray"/> </DataTrigger> </Style.Triggers> </Style> </DataGrid.RowStyle> </DataGrid> 
+7
source share

All Articles