title: How to add wpf control to particular grid row and cell during runtime?
body: <p>I have the following grid in my WPF "Window" (yes the class Window);</p>
  
  <pre><code>&lt;Grid Name="RequiredGrid"&gt;
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width="70" /&gt;
                  &lt;ColumnDefinition Width="*" /&gt;
              &lt;/Grid.ColumnDefinitions&gt;
          &lt;/Grid&gt;
  </code></pre>
  
  <p>Depending on whats passed into the window, I want to add items into this grid one row at a time.  Namely, I want to add a Label in the left column and a TextBox in the right column.  I believe I know how to add new rows for holding new data by doing the following in the code behind:</p>
  
  <pre><code>RequiredGrid.RowDefinitions.Add(new RowDefinition());
  </code></pre>
  
  <p>Problem is, after I've created my Label and my TextBox.</p>
  
  <pre><code>Label AttrLabel = new Label();
  TextBox AttrTextBox = new TextBox();
  </code></pre>
  
  <p>I don't really know how to get it into the Window so it gets displayed.  I've seen some threads that say, do something like this:</p>
  
  <pre><code>this.Controls.Add(AttrLabel);
  this.Controls.Add(AttrTextBox);
  </code></pre>
  
  <p>There are two problems with this.  1) My Window class doesn't have this "Controls" property or whatever.  And 2) This wouldn't help me specify the row and column of each UI item.</p>
  
  <p>Now in XAML, Id be easy to specify the row and column with something like this:</p>
  
  <pre><code> &lt;Label Grid.Column="0" Grid.Row="0"/&gt;
  </code></pre>
  
  <p>This defeats the "dynamic-ness" of my intent here though. Does anyone know how I can get my dynamicaly created UI elements to display in my Window and specify which row and column it will show up in the grid.</p>