title: Programmatically setting the content of a ContentControl in WPF
body: <p>I have a UserControl  named "WorkspaceView" and its only purpose is to show other views as tabs. Call these views ViewA, ViewB etc. Which of these views to present should be determined on runtime, so I figured I needed a control that can present ... well ..stuff. <br>
  ContentControl to the rescue. Except ... I can't make it work. I'm trying to new up a usercontrol of type ViewA in the code behind and assign it to my MyContent, which is the ContentControl. I've tried:</p>
  
  <pre><code>public WorkspaceView()
  {
      InitializeComponent();
      DataContext = new View(A); //Hoping that the DataContext will propagate down
  }
  </code></pre>
  
  <p>Second attempt was </p>
  
  <pre><code>public WorkspaceView()
  {
      InitializeComponent();
      var binding = new Binding {Source = new ViewA()};
      MyContent.SetBinding(ContentControl.ContentProperty, binding);
  }
  </code></pre>
  
  <p>In both cases, I see an empty box, but since I've hard wired a TextBlock into ViewA, I'd expect it to show me that text. What am I doing wrong? </p>
  
  <p>Despite knowing that MVVM is the preferred way to develop WPF applications, I'd prefer to see how I can do this with code behind files. Later on, I will redo the application with MVVM, but first I need to get some basic understanding of WPF.  </p>
  
  <p><br>
  In response to the suggestions so far, I've tried </p>
  
  <pre><code>MyContent.Content = new ViewA();
  </code></pre>
  
  <p>but still I the text that is in ViewA does not appear. I've also at the bottom of this post included a screenshot of what the application renders.</p>
  
  <h2>WorkspaceView</h2>
  
  <p><img src="https://i.stack.imgur.com/Dagva.png" alt="enter image description here"></p>
  
  <h2>Resource file</h2>
  
  <p><img src="https://i.stack.imgur.com/nYaZZ.png" alt="enter image description here"></p>
  
  <h2>What is rendered</h2>
  
  <p><img src="https://i.stack.imgur.com/qW85J.png" alt="enter image description here"></p>