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

后端 未结 5 376
陌清茗
陌清茗 2020-12-15 17:17

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

5条回答
  •  一生所求
    2020-12-15 17:42

    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;
    

提交回复
热议问题