.net 在 WPF Datagrid 中着色网格线
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5076748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Coloring Gridlines in WPF Datagrid
提问by Hulda
How can I set the color of the gridlines of a wpf datagrid? I can hide these lines with the property GridLinesVisibility, but I don't know how to color them. I tried it with the Borderbrush of rows and cells but I didn't succeed.
如何设置 wpf 数据网格的网格线的颜色?我可以用属性隐藏这些线条GridLinesVisibility,但我不知道如何给它们上色。我用行和单元格的 Borderbrush 进行了尝试,但没有成功。
回答by Fredrik Hedblad
You have the Properties HorizontalGridLinesBrushand VerticalGridLinesBrush
你有属性HorizontalGridLinesBrush和VerticalGridLinesBrush
Example
例子
<DataGrid HorizontalGridLinesBrush="Green"
VerticalGridLinesBrush="Red"
...>
回答by biju
You can change the VerticalGridLinesBrushand HorizontalGridLinesBrushproperties of the Datagrid
您可以更改Datagrid的VerticalGridLinesBrush和HorizontalGridLinesBrush属性
<Window.Resources>
<SolidColorBrush x:Key="RedGridLine" Color="#FFFF4444" />
<SolidColorBrush x:Key="BlueGridLine" Color="#554444FF"/>
</Window.Resources>
<my:DataGrid VerticalGridLinesBrush="{StaticResource RedGridLine}"
HorizontalGridLinesBrush="{StaticResource BlueGridLine}" >
For more
更多
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0202b0dd-38d9-4ad7-8576-d115922aeeec/
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0202b0dd-38d9-4ad7-8576-d115922aeeec/
回答by ΩmegaMan
To supplement the current answers, one can change the opacity at the same time in the resource to affect the gridlines:
为了补充当前的答案,可以同时更改资源中的不透明度以影响网格线:
<Window.Resources>
<SolidColorBrush x:Key="StackOverflowGray" Color="LightGray" Opacity=".3" />
</Window.Resources>
...
...
Then the following usages has a lighter border shown in the datagrid:
然后以下用法在数据网格中显示较浅的边框:
<DataGrid GridLinesVisibility="All"
HorizontalGridLinesBrush="{StaticResource StackOverflowGray}"
VerticalGridLinesBrush="{StaticResource StackOverflowGray}"

