alkk
alkk

Reputation: 341

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

Upvotes: 3

Views: 4377

Answers (1)

kennyzx
kennyzx

Reputation: 12993

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>

Upvotes: 5

Related Questions