Question: I have a `WPF` `DataGrid`, In that I can set `DataGrid` `RowBackground` color, alternative `RowBackground` color independently. Likewise I want to set `DataGrid` `RowForeground` color, alternative `RowForeground` color independently.

How can I achieve this with simple and optimal way? 

I am binding DataGrid dynamically, XAML static resource wont help me here.

Answer: 
you can use the AlternationIndex prop like that:

```
   <Style TargetType="{x:Type DataGridRow}">
  <Style.Triggers>
      <Trigger Property="ItemsControl.AlternationIndex" Value="0">
          <Setter Property="Foreground" Value="Red" />
     </Trigger>
  </Style.Triggers>
</Style>

```
You can set a style trigger that will change the row's foreground color based on its background color.

Example, by default, the row's foreground color will be Blue, but if it's Background color is White, then its foreground color will be Red. See below. 

```
  <DataGrid ...>
        <DataGrid.RowStyle>
            <Style TargetType="DataGridRow">
                <Setter Property="TextElement.Foreground" Value="Blue"/>
                <Style.Triggers>
                    <Trigger Property="TextElement.Background" Value="White">
                        <Setter Property="TextElement.Foreground" Value="Red"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </DataGrid.RowStyle>
        ...
    </DataGrid>

```