WPF中Grid实现网格,表格样式通用类_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > WPF中Grid实现网格,表格样式通用类

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

 2016/5/12 5:31:44  WORTLIU  程序员俱乐部  我要评论(0)
  • 摘要:///<summary>///给Grid添加边框线///</summary>///<paramname="grid"></param>publicstaticvoidInsertFrameForGrid(Gridgrid){varrowcon=grid.RowDefinitions.Count;varclcon=grid.ColumnDefinitions.Count;for(vari=0;i<rowcon+1;i++
  • 标签:实现 表格
/// <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);
            }
        }

 

上一篇: Mac 下安装Ruby环境 下一篇: MongoDB集群配置
发表评论
用户名: 匿名