WPF中Grid实现网格,表格样式通用类(转)

Posted ExplorerMan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF中Grid实现网格,表格样式通用类(转)相关的知识,希望对你有一定的参考价值。

/// <summary>
/// 给Grid添加边框线
/// </summary>
/// <param name="grid"></param>
public static void InsertFrameForGrid(Grid grid)
{
var rowcon = grid.RowDefinitions.Count;
var clcon = grid.ColumnDefinitions.Count;
for (var i = 0; i < rowcon + 1; i++)//行循环添加border
{
var border = new Border
{
BorderBrush = new SolidColorBrush(Colors.SlateGray),
BorderThickness = i == rowcon ? new Thickness(0, 0, 0, 1) : new Thickness(0, 1, 0, 0)
};

Grid.SetRow(border, i);
Grid.SetColumnSpan(border, clcon);
grid.Children.Add(border);
}

for (var j = 0; j < clcon + 1; j++)//列循环添加border
{
var border = new Border
{
BorderBrush = new SolidColorBrush(Colors.SlateGray),
BorderThickness = j == clcon ? new Thickness(0, 0, 1, 0) : new Thickness(1, 0, 0, 0)
};
Grid.SetColumn(border, j);
Grid.SetRowSpan(border, rowcon);
grid.Children.Add(border);
}
}

以上是关于WPF中Grid实现网格,表格样式通用类(转)的主要内容,如果未能解决你的问题,请参考以下文章

WPF Grid - 如何为一列应用样式?

WPF C# 如何在动态添加的grid控件中添加某个网格中的image控件的单击事件?

在 extjs 中渲染表格后使用不同样式设置两个单独的网格单元格

WPF如何使曲面带网格

WPF如何使曲面带网格

VS2010 去除WPF设计视图中的网格线