WPF DataGridCell BorderThickness = 0不起作用

时间:2015-01-27 01:55:48

标签: wpf datagrid datagridcell

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>

结果:

enter image description here

1 个答案:

答案 0 :(得分:2)

这可以通过将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>
相关问题