如何突出显示网格控件的边框线
我编写了一些代码,以便将 100 x 100 个单元格添加到网格中。问题是我想突出显示分割网格的行/列的线。
我应该使用什么属性,或者我应该如何做?
下面是创建网格单元的代码:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
for (int i = 0; i < 100 ; i++)
layoutGrid.RowDefinitions.Add( new RowDefinition { } );
for (int i = 0; i < 100; i++)
layoutGrid.ColumnDefinitions.Add(new ColumnDefinition { });
}
}
I have wrote some code in order to add 100 x 100 cells to a grid. The thing is that I would like to highlight the lines that split the rows/column of the grid.
What properties should I use, or how should I do that?
Bellow is the code for creating the grid cells :
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
for (int i = 0; i < 100 ; i++)
layoutGrid.RowDefinitions.Add( new RowDefinition { } );
for (int i = 0; i < 100; i++)
layoutGrid.ColumnDefinitions.Add(new ColumnDefinition { });
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试几种方法。如果您查看 Grid.cs,请参阅 Brushes.Blue 和 Brushes.Blue 。 Brushes.Yellow 纯色构成了当您在下面的源代码中启用 ShowGridLines="True" 时看到的破折号?您可以将它们设置为不同的颜色(使它们具有相同的颜色,而不必像 Brushes.Gray 那样对其进行编辑,或者您可以省略破折号,绘制一条线,甚至可以使用自定义画笔资源,例如 。
或者,您可以在 XAML 中展示一个技巧(因为我已经在其他地方的过去的帖子中制作了一个示例),您可以使用一组 BorderBrush 和 BorderThickness 和 span 增量来进行边框控制 跨越边界像这个例子一样的单元格和列;
或者使用 DataGrid 的 XAML;
希望这有帮助,祝你好运!
There's a couple ways you can try. If you take a look at Grid.cs, see the Brushes.Blue & Brushes.Yellow solid colors that make up the dashes you see when you enable ShowGridLines="True" in the source below? You can set those over to a different color (make them both the same color to not have to edit it much like Brushes.Gray, or you can omit the dash, draw a single line, and could even use a custom brush resource like a gradient.
Or there's a trick you can do shown in XAML (because I had already slapped an example together for a past post elsewhere) where you take a border control with a set BorderBrush & BorderThickness and span incremental borders across the cells & columns like this example;
Or with XAML for DataGrid;
Hope this helps and best of luck!