首页 > Windows开发 > 详细

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

时间:2016-05-11 19:37:44      阅读:515      评论: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/5483206.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!