码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2016-06-02 13:04:01      阅读:1266      评论:0      收藏:0      [点我收藏+]

标签:

/// <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实现网格,表格样式通用类(转)

标签:

原文地址:http://www.cnblogs.com/ExMan/p/5552547.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!