title: Where to put WPF Dynamic Control Creation Code
body: <p>I am just in the process of teaching myself WPF. I have reached the point of adding controls dynamically and have hit a brick wall on something really simple. I code that should create a button (shown below):</p>
  
  <pre><code>Button button = new Button() { Height = 80, Width = 150, Content = "Test" };
  parentControl.Add(button);
  </code></pre>
  
  <p>My question is what is <code>parentControl</code> actually called? I am using the standard Visual Studio 2012 WPF template and my main window is called <code>MainWindow</code>. I have no objects in the Window besides what comes in the template</p>
  
  <p>So far I have looked at:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/2491807/wpf-runtime-control-creation">WPF runtime control creation</a></li>
  <li><a href="https://stackoverflow.com/questions/1147829/dynamic-control-creation-in-wpf">Dynamic control creation in WPF</a></li>
  <li><a href="https://stackoverflow.com/questions/13156445/wpf-mvvm-dynamic-control-creation">WPF MVVM Dynamic control creation</a></li>
  <li><a href="https://stackoverflow.com/questions/433833/dynamic-creation-of-control">Dynamic creation of control</a></li>
  <li><a href="https://stackoverflow.com/questions/2654730/where-should-i-put-wpf-specific-code-when-using-mvvm">Where should I put WPF specific code when using MVVM?</a></li>
  <li><a href="https://stackoverflow.com/questions/13859730/steps-of-control-creation-process-wpf">Steps Of Control Creation Process WPF</a></li>
  <li><a href="https://stackoverflow.com/questions/1029131/where-to-put-code-in-primarily-windowless-wpf-app">Where to put code in (primarily) windowless WPF app?</a></li>
  </ul>
  
  <p>The closest I have found it: <a href="https://stackoverflow.com/questions/2491807/wpf-runtime-control-creation">WPF runtime control creation</a>. </p>
  
  <p>All of these questions just assume you know such a basic thing but I don't. Please help.</p>