Coloring Gridlines in WPF Datagrid

.NetWpfXamlDatagrid

.Net Problem Overview


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.

.Net Solutions


Solution 1 - .Net

You have the Properties HorizontalGridLinesBrush and VerticalGridLinesBrush

Example

<DataGrid HorizontalGridLinesBrush="Green"
          VerticalGridLinesBrush="Red"
          ...>

Solution 2 - .Net

You can change the VerticalGridLinesBrush and HorizontalGridLinesBrush properties of the Datagrid

 <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://www.c-sharpcorner.com/UploadFile/dpatra/1803/

Solution 3 - .Net

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}"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHuldaView Question on Stackoverflow
Solution 1 - .NetFredrik HedbladView Answer on Stackoverflow
Solution 2 - .NetbijuView Answer on Stackoverflow
Solution 3 - .NetΩmegaManView Answer on Stackoverflow