Silverlight 在Grid中动态增加控件并排版

来源:互联网 发布:栈的算法描述 编辑:程序博客网 时间:2024/05/21 11:01

for (int j = 0; j < numrows; j++)
{
     RowDefinition rd 
= new RowDefinition();
     LayoutRoot.RowDefinitions.Add(rd);

     ColumnDefinition cd 
= new ColumnDefinition();
     LayoutRoot.ColumnDefinitions.Add(cd);

    
for (int i = 0; i < numcells; i++)
     {
          TextBox tb 
= new TextBox();
          tb.Width 
= 110;
          tb.Height 
= 30;
          tb.Text 
= "row   " + j.ToString() + ",   cell   " + i.ToString();

          LayoutRoot.Children.Add(tb);
          LayoutRoot.SetValue(Grid.ShowGridLinesProperty, 
true); //显示网格
          tb.SetValue(Grid.ColumnProperty, i);
          tb.SetValue(Grid.RowProperty, j);
     }

}


转自:http://www.cnblogs.com/star250/archive/2009/04/19/1439181.html

原创粉丝点击