Creating RowDefinitions and ColumnDefinitions in code

windows-phone, xaml

Solution

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);

Have a look at the code at the bottom of this MSDN page

Problem

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); ``` But I don't know how to create RowDefinitions and ColumnDefinitions.

Original source