title: How do I generate WPF controls through code
body: <p>I was trying to get my head around XAML and thought that I would try writing some code.  </p>
  
  <p>Trying to add a grid with 6 by 6 column definitions then add a text block into one of the grid cells. I don't seem to be able to reference the cell that I want. There is no method on the grid that I can add the text block too.  There is only grid.children.add(object), no Cell definition.</p>
  
  <p>XAML:</p>
  
  <pre><code>&lt;Page x:Class="WPF_Tester.Page1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Page1"
      Loaded="Page_Loaded"&gt;
  
  &lt;/Page&gt;
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>private void Page_Loaded(object sender, RoutedEventArgs e)
  {
      //create the structure
      Grid g = new Grid();
      g.ShowGridLines = true;
      g.Visibility = Visibility.Visible;
  
      //add columns
      for (int i = 0; i &lt; 6; ++i)
      {
          ColumnDefinition cd = new ColumnDefinition();
          cd.Name = "Column" + i.ToString();
  
          g.ColumnDefinitions.Add(cd);
      }
      //add rows
      for (int i = 0; i &lt; 6; ++i)
      {
          RowDefinition rd = new RowDefinition();
          rd.Name = "Row" + i.ToString();
  
          g.RowDefinitions.Add(rd);
      }
      TextBlock tb = new TextBlock();
      tb.Text = "Hello World";
  
      g.Children.Add(tb);
  }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>Here is the spooky bit:</p>
  
  <ul>
  <li><p>Using VS2008 Pro on XP</p></li>
  <li><p>WPFbrowser Project Template (3.5 verified)</p></li>
  </ul>
  
  <p>I don't get the methods in autocomplete.</p>