1

在 WPF 'DataGrid' 中,水平网格线的颜色可以通过HorizontalGridLinesBrush属性进行修改。

某些项目的布尔属性设置为 true,因此我想将水平网格线刷设置为另一种颜色来突出显示它们。

是否可以仅为某些行更改水平网格线的颜色?

4

1 回答 1

3

DataGrid.HorizontalGridLinesBrush设置为每行,因此您不能每行更改它,但您可以通过禁用水平网格线并创建自定义样式DataGrid来替换默认的水平线行为DataGridRow

<DataGrid ... GridLinesVisibility="Vertical">
    <DataGrid.RowStyle>
        <Style TargetType="{x:Type DataGridRow}">
            <Setter Property="BorderThickness" Value="0,0,0,1"/>
            <Setter Property="BorderBrush" Value="Black"/>
            <Style.Triggers>

                <!-- this will trigger when row is selected -->
                <Trigger Property="IsSelected" Value="True">                        
                    <Setter Property="BorderBrush" Value="Red"/>
                </Trigger>

                <!-- this will trigger when Highlight property of the view model is true -->
                <DataTrigger Binding="{Binding Highlight}" Value="True">
                    <Setter Property="BorderBrush" Value="Green"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </DataGrid.RowStyle>
</DataGrid>
于 2014-11-14T14:12:26.897 回答