C# 如何以一像素宽度(WPF DataGrid)设置网格线?
我正在使用WPF datagrid显示一些数据,我希望网格线的厚度等于一个像素,但每个单元格显示不需要的边框。如何去掉它并将所有线条的厚度设置为一个像素(如WinForms中的DataGridView)C# 如何以一像素宽度(WPF DataGrid)设置网格线?,c#,wpf,datagrid,C#,Wpf,Datagrid,我正在使用WPF datagrid显示一些数据,我希望网格线的厚度等于一个像素,但每个单元格显示不需要的边框。如何去掉它并将所有线条的厚度设置为一个像素(如WinForms中的DataGridView) XAML: 结果: 这可能对你有好处 <DataGrid.CellStyle> <Style TargetType="DataGridCell"> <Setter Property="BorderThickness" Value="1,0,
XAML:
结果:
这可能对你有好处
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="BorderThickness" Value="1,0,0,1"/>
<Setter Property="BorderBrush" Value="Black"/>
</Style>
</DataGrid.CellStyle>
试试这个:
<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
设置相同的属性,这就是解决方案!
Settig参数RenderOptions.EdgeMode=“别名”
非常感谢David Kossoglyad提供此解决方案
<DataGrid RenderOptions.EdgeMode="Aliased" UseLayoutRounding="True" ....>
当我将属性GridLinesVisibility设置为“无”值时,所有网格线都被删除。我需要网格线,但在一个像素的宽度。问题并没有解决,但加剧了。设置边界后,边界变得更厚,现在等于2个像素。必须将1,1,1,1更改为1,0,0,1,然后查看它是否有用。当我将BorderThickness值设置为“1,0,0,1”时,网格线返回到其原始状态(如我问题中的图片所示)。它可能是特定于操作系统的,只是在win10上尝试了示例,但没有这样的阴影。不幸的是,没有帮助
<DataGrid RenderOptions.EdgeMode="Aliased" UseLayoutRounding="True" ....>