Search code examples
wpfdatagridrow

Conditional text-color for the DataGrid rows?


I have a datagrid which is bound to a database table. I need to change the forecolor of a row to blue depending on there is a value in one of its columns. Is there a way I can do this? I tried IValueConverter, but I presume I can use this only for one cell at a time.


Solution

  • <DataGrid>
        <DataGrid.CellStyle>
            <Style TargetType="{x:Type DataGridCell}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding SomeProperty}" Value="SomeValue" >
                        <Setter Property="Foreground" Value="Blue" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </DataGrid.CellStyle>
    </DataGrid>