在代码中创建 RowDefinitions 和 ColumnDefinitions [英] Creating RowDefinitions and ColumnDefinitions in code
本文介绍了在代码中创建 RowDefinitions 和 ColumnDefinitions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为 windows-phone 开发应用程序,我想创建 2 行和 2 列的表我为此表创建了 xaml 代码
I developing application for windows-phone, I want to create table with 2 rows an 2 columns I create xaml code for this table
<Grid Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions/>
</Grid>
我想用代码创建这个网格
I want to create this Grid in code
Grid chat_userpicgrid = new Grid();
newgrid.Children.Add(chat_userpicgrid);
但我不知道如何创建 RowDefinitions 和 ColumnDefinitions.
But I don't know how to create RowDefinitions and ColumnDefinitions.
推荐答案
Grid newGrid = new Grid();
newGrid.Background = new SolidColorBrush(Colors.White);
newGrid.ColumnDefinitions.Add(new ColumnDefinition());
newGrid.ColumnDefinitions.Add(new ColumnDefinition());
newGrid.RowDefinitions.Add(new RowDefinition());
newGrid.RowDefinitions.Add(new RowDefinition());
在特定单元格中定位元素:
To position elements in specific cells:
Grid chat_userpicgrid = new Grid();
Grid.SetColumn(chat_userpicgrid, 1);
Grid.SetRow(chat_userpicgrid, 1);
newGrid.Children.Add(chat_userpicgrid);
这篇关于在代码中创建 RowDefinitions 和 ColumnDefinitions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文