Pages

Tuesday 19 March 2013

WPF DataGrid RowStyle

To change the style of the rows in a DataGrid use the DataGrid.RowStyle and set the required properties. In order to retain the bulk of the standard DataGridRow style, including alternating row colours and mouseover row highlighting add the BasedOn attribute to the Style tag.

<DataGrid.RowStyle>
  <Style TargetType="DataGridRow"
            BasedOn="{StaticResource {x:Type DataGridRow}}">
  <Style.Triggers>
    <DataTrigger Binding="{Binding BeingActioned}"
                    Value="True">
      <Setter Property="FontStyle"
                 Value="Italic" />
      <Setter Property="Foreground"
                 Value="Silver" />
      </DataTrigger>
    </Style.Triggers>
  </Style>
</DataGrid.RowStyle>