Alex Rivera | Logout

How can I change the color of the gridlines of a Grid in WPF?

Asked 2009-03-03T12:33:45.817
30

I have a Grid (not a DataGrid, but a real Grid), with GridLines set to True. How can I change the color of the gridlines? Hardcoded in XAML is ok, since it is just for development-reasons.

<Grid ShowGridLines="True" />
Edit
Report

1 Answer

13
var T = Type.GetType("System.Windows.Controls.Grid+GridLinesRenderer," +
    " PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");

var GLR = Activator.CreateInstance(T);
GLR.GetType().GetField("s_oddDashPen", BindingFlags.Static | BindingFlags.NonPublic).SetValue(GLR, new Pen(Brushes.Black, 1.0));
GLR.GetType().GetField("s_evenDashPen", BindingFlags.Static | BindingFlags.NonPublic).SetValue(GLR, new Pen(Brushes.Black, 1.0));

myGrid.ShowGridLines = true;
answered 2012-06-03T10:58:17.807

Your Answer