Search code examples
c#wpfdatagridwpfdatagridgridlines

How to set DataGrid line color in DataTrigger?


How can I set a different grid line color for some rows in DataGrid through DataTrigger?

I tried this:

<DataGrid ...>
    <DataGrid.RowStyle>
        <Style TargetType="DataGridRow">
            <Style.Triggers>
                <DataTrigger
                    Binding="{Binding in_stock, Converter={conv:LessThan 4}}"
                    Value="True">
                    <Setter Property="BorderBrush" Value="Red" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </DataGrid.RowStyle>
</DataGrid>

But the grid lines are all the same, default color.


Solution

  • I haven't found a way to hide the grid line at each separate row but I bypassed it by removing all horizontal grid lines through GridLinesVisibility="Vertical" and creating one-pixel bottom border for each DataGridCell where it is desired.