【问题标题】:How to set grid lines in a one pixel width (WPF DataGrid)?如何设置一个像素宽度的网格线(WPF DataGrid)?
【发布时间】:2016-11-28 21:47:11
【问题描述】:

我正在使用 WPF 数据网格来显示一些数据,并且我希望网格线的粗细等于一个像素,但是每个单元格都显示了不需要的边框。如何摆脱它并将所有线条的粗细设置为一个像素(如在 WinForms 中的 DataGridView 中)?

XAML:
<DataGrid HeadersVisibility="Column" SelectionUnit="Cell">
   <DataGrid.Columns>
      <DataGridTextColumn Header="ID" Binding="{Binding ID}"/>                                    
      <DataGridTextColumn Header="Description" Binding="{Binding Description}"/>
   </DataGrid.Columns>
</DataGrid>

结果:

【问题讨论】:

  • 它可能是特定于操作系统的,只是在 win10 下尝试了示例,并没有这样的阴影。

标签: c# wpf datagrid


【解决方案1】:

这就是解决方案! Settig 参数 RenderOptions.EdgeMode="Aliased" 非常感谢 David Kossoglyad 提供的解决方案。

<DataGrid RenderOptions.EdgeMode="Aliased" UseLayoutRounding="True" ....>

【讨论】:

    【解决方案2】:

    这可能对你有用

    <DataGrid.CellStyle>
        <Style TargetType="DataGridCell">
            <Setter Property="BorderThickness" Value="1,0,0,1"/>
            <Setter Property="BorderBrush" Value="Black"/>
        </Style>
    </DataGrid.CellStyle>
    

    【讨论】:

    • 当我将属性 GridLinesVisibility 设置为“无”值时,所有网格线都被删除了。我需要网格线,但宽度只有一个像素。
    • 问题没有解决,反而加剧了。设置后 边框变得更粗,现在等于 2像素
    • 把 1,1,1,1 改成 1,0,0,1 看看有没有帮助
    • 它没有帮助。当我将 BorderThickness 值设置为“1,0,0,1”时,网格线恢复到原来的状态(如我问题中的图片所示)
    【解决方案3】:

    试试这个:

        <DataGrid.CellStyle>
            <Style TargetType="DataGridCell">
                <Setter Property="Effect">
                    <Setter.Value>
                        <DropShadowEffect BlurRadius="1" Opacity="0" ShadowDepth="0"/>
                    </Setter.Value>
                </Setter>
            </Style>
        </DataGrid.CellStyle>
    

    如果这无济于事,请尝试为 DataGrid.RowStyle 设置相同的属性。

    【讨论】:

    • 很遗憾没有帮助
    猜你喜欢
    • 2014-03-18
    • 1970-01-01
    • 2017-02-01
    • 2020-02-15
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多