title: Programmatically add a TextBlock to a DataTemplate
body: <pre><code>&lt;DataTemplate&gt;
      &lt;TextBlock x:Name="Txt" Text="{Binding fieldA}" /&gt;
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>I want to do the equivalent of the above XAML programatically (There is more to the XAML, I have only shown the relevant bits). So far I have got:</p>
  
  <pre><code>DataTemplate newDataTemplate = new DataTemplate();
  TextBlock newTextBlock = new TextBlock();
  newTextBlock.SetBinding(TextBlock.TextProperty, new Binding("fieldA"));
  newTextBlock.Name = "txt";
  </code></pre>
  
  <p>So how do I now add the TextBlock to the DataTemplate.. i.e. I want to do something like:</p>
  
  <pre><code>newDataTemplate.children.Add(TextBlock)
  </code></pre>