Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF DataGridCell BorderThickness=0 doesn't work

DataGridColumnHeader.BorderThickness=0 works for me, but not DataGridRow or DataGridCell, any thought?

<DataGrid x:Name="dg">
    <DataGrid.Resources>
        <Style TargetType="DataGrid">
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="BorderThickness" Value="0" />
        </Style>
        <Style TargetType="DataGridColumnHeader">
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="BorderBrush" Value="Black" />
            <Setter Property="BorderThickness" Value="0 0 0 1" />
        </Style>
    </DataGrid.Resources>
</DataGrid>

The result:

enter image description here

like image 937
alkk Avatar asked Mar 23 '26 10:03

alkk


1 Answers

This can be achieved by setting GridLinesVisibility property to None.

<DataGrid x:Name="dg" DataGrid.GridLinesVisibility="None">
    ...

You could play with the following snippet to understand which part of DataGrid is affected by the BorderThickness settings- there are 3 border styles, each has a different color.

<DataGrid x:Name="dg" >
    <DataGrid.Resources>
        <Style TargetType="DataGridCell">
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="BorderBrush" Value="Red" />
        </Style>
        <Style TargetType="DataGrid">
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="BorderBrush" Value="Green" />
        </Style>
        <Style TargetType="DataGridColumnHeader">
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="BorderBrush" Value="Black" />
            <Setter Property="BorderThickness" Value="0 0 0 1" />
        </Style>
    </DataGrid.Resources>
</DataGrid>
like image 79
kennyzx Avatar answered Mar 25 '26 02:03

kennyzx