Martin Heralecký
Martin Heralecký

Reputation: 5789

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.

Upvotes: 0

Views: 587

Answers (2)

Martin Heraleck&#253;
Martin Heraleck&#253;

Reputation: 5789

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.

Upvotes: 0

Justin CI
Justin CI

Reputation: 2741

Just try this method

 <Window.Resources>

        <Style x:Key="HighLightCell" TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding In_stock}" Value="True">
                    <Setter Property="BorderBrush" Value="Red" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

</Window.Resources>
<Grid>
    <DataGrid Grid.Row="3"
      ItemsSource="{Binding DataGridPersonList}"
      SelectedItem="{Binding SelectedDataGridPerson}"
    CellStyle="{StaticResource HighLightCell}"
      AutoGenerateColumns="False"
    >

        <DataGrid.Columns>
            <DataGridTextColumn Header="Status"
                  Binding="{Binding Status}" Width="*" >

            </DataGridTextColumn>

            <DataGridTextColumn Header="Name"
                  Binding="{Binding Name}" Width="*" />

        </DataGrid.Columns>

    </DataGrid>


</Grid>

Upvotes: 1

Related Questions