Windows Phone 7使用C#通过后台动态生成Grid网格布局

转自:http://www.silverlightchina.net/html/zhuantixilie/winphone7/2012/0905/18679.html

一、创建相关对象,并定义Grid中的列属性 GridforwardAndReply= new Grid(); //创建Grid对象 forwardAndReply.Margin= new Thickness(0,10,0,5); forwardAndReply.HorizontalAlignment=HorizontalAlignment.Right; forwardAndReply.Height=30; //创建第一个ColumnDefinition ColumnDefinitionfirstColum
  

  一、创建相关对象,并定义Grid中的列属性

Grid forwardAndReply =  new Grid(); //创建Grid对象

 forwardAndReply.Margin =  new Thickness(0, 10, 0, 5);
 forwardAndReply.HorizontalAlignment = HorizontalAlignment.Right;
 forwardAndReply.Height = 30;

//创建第一个ColumnDefinition
 ColumnDefinition firstColumnDefinition =  new ColumnDefinition(); //定义Grid列属性对象
 firstColumnDefinition.Width =  new GridLength(125, GridUnitType.Pixel); //初始化GridLength并设置指定的值
 forwardAndReply.ColumnDefinitions.Add(firstColumnDefinition); //添加ColumnDefinition到Grid的列属性集合中

//创建第二个ColumnDefinition
ColumnDefinition secondColumnDefinition =  new ColumnDefinition();
secondColumnDefinition.Width =  new GridLength(125, GridUnitType.Pixel);
forwardAndReply.ColumnDefinitions.Add(secondColumnDefinition);

  二、将UI元素添加到指定的列中

  RichTextBox content = new RichTextBox();//创建RichTextBox控件对象

  Grid.SetColumn(forward,0);//设置即将要添加的UI元素所在的列,0为第一列

  forwardAndReply.Children.Add(forward);//添加UI元素到Grid中

  本文来自xiaofoyuan的博客,原文地址:http://www.cnblogs.com/xiaofoyuan/archive/2012/07/09/2582421.html


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值