WPF DataGridCell border厚度=0不工作。

时间:2021-12-10 14:13:07

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

DataGridColumnHeader。边界值=0对我有用,但不是DataGridRow或DataGridCell,有什么想法吗?

<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:

结果:

WPF DataGridCell border厚度=0不工作。

1 个解决方案

#1


2  

This can be achieved by setting GridLinesVisibility property to None.

这可以通过将GridLinesVisibility属性设置为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的哪个部分受到边界设置的影响——有3种边框样式,每种都有不同的颜色。

<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>

#1


2  

This can be achieved by setting GridLinesVisibility property to None.

这可以通过将GridLinesVisibility属性设置为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的哪个部分受到边界设置的影响——有3种边框样式,每种都有不同的颜色。

<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>