Try something like this:
DockPanel dp = new DockPanel();
dp.Background= Brushes.CadetBlue;
dp.Width=50;
dp.Height=50;
Grid g =new Grid();
Grid.RowDefinitions.Add(newRowDefinition()); //add one for each row
newRowDefinition());Grod.RowDefinitions.Add(
Grid.ColumnDefinitions.Add(newColumnDefinition()); //add one for each column
Grid.ColumnDefinitions.Add(
newColumnDefinition());Grid.ColumnDefinitions[0].Width =
newGridLength(10, GridUnitType.Pixel); //define size for each columnGrid.ColumnDefinitions[1].Width =
newGridLength(1, GridUnitType.Star);Grid.RowDefinitions[0].Height = newGridLength(10, GridUnitType.Pixel); //define size for each row
Grid.RowDefinitions[1].Height =
newGridLength(1, GridUnitType.Star);Grid.SetRow(dp,1); //set starting row 0 to n-1
Grid.SetColumn(dp,1); //set starting column 0 to n-1
Grid.SetColumnSpan(dp, 1); number of columns
Grid.SetRowSpan(dp, 1); //number of rows
grdMap.Children.Add(g);
Tom