WPF DataGridCell BorderThickness=0 不起作用。

3

DataGridColumnHeader.BorderThickness=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>

结果如下:

在此输入图片描述

1个回答

4
这可以通过将GridLinesVisibility属性设置为None来实现。
<DataGrid x:Name="dg" DataGrid.GridLinesVisibility="None">
    ...

您可以使用以下代码片段进行测试以了解 DataGrid 的哪个部分受到 BorderThickness 设置的影响 - 其中有 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>

非常感谢!你能帮我解决这个问题吗?链接 - alkk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接