title: How to add controls / Elements to a form in the WPF C# code?
body: <p>Is there a way to add a control like in Win Forms C# <code>Button b = new Button();</code> and then add it just like <code>Form1.Controls.Add(b);</code></p>
  
  <p>I can't do this in WPF because I don't have a Controls attribute in the Window class. How can I do this. I read this of just putting a Panel, dock it to fill and then there I use this:</p>
  
  <pre><code>myPanel.Children.Add(b);
  </code></pre>
  
  <p>But then it comes to me again. How do I create and add a Panel and dock it to fill?</p>
  
  <p>If I use <code>Panel p = new Panel();</code> it marks error. And how do I add the panel to my MainWindow?</p>