zoukankan      html  css  js  c++  java
  • c# 创建grid行列 并添加控件

    用c#添加行跟列

    先要想清楚要分几行几列

    int row =2;

    int column=2;

    xakl页面的grid x:Name="gridPrint"

    gridPrint在使用过程中可能多次被使用添加子集或者行跟列 

    所用使用之前都要先清空一下

    gridPrint.Children.Clear();
    gridPrint.RowDefinitions.Clear();
    gridPrint.ColumnDefinitions.Clear();

    创建一个2行2列的grid

    利用两个循环添加行跟列

      for (int i = 0; i < row; i++)
                {
                    gridPrint.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
                }

      for (int i = 0; i < column; i++)
                {
                    gridPrint.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
                }

    添加完成之后  就是要填充子集 

      再用两个for循环填充grid

    这样添加4个grid  

     for (int i = 0; i < row; i++)
                {
                    for (int y = 0; y < column; y++)
                    {
                        Grid l = new Grid();
                        Grid.SetRow(l, i);
                        Grid.SetColumn(l, y);
                        gridPrint.Children.Add(l);
                    }
                }

    添加完之后如果还要添加控件  

    就会用到这样的格式 ((Grid)gridPrint.Children[0])  这就是gridPrint的子集的第一个控件 索引都是从0开始的

  • 相关阅读:
    Android MulticastSocket IP组播
    IP组播技术介绍及实现例子
    机器学习:多变量线性回归
    慘挂阿里笔试题
    Android使用am命令实现拨打电话、打开应用
    社交O2O的进化
    hibernate4中HHH000273的错误
    Java中常见的排序算法
    Axure实现淡入淡出效果
    Ubuntu虚拟机+ROS+Android开发环境配置笔记
  • 原文地址:https://www.cnblogs.com/v587yy/p/7743125.html
Copyright © 2011-2022 走看看