title: Programatically binding to a changing ViewModel
body: <p>I am creating an application that works like the 'wizard' component of some microsoft applications. To represent this, I have two ViewModels:</p>
  
  <pre><code>class WizardVm {
      public string Name { get; set; }
      public ICommand QuitCommand { get { /* ommitted */ } }
      public WizardStepVm CurrentStep { get; set; }
  }
  
  class WizardStepVm {
      public string StepName { get; set; }
      public string StepText {get; set; }
  }
  </code></pre>
  
  <p>In the view, <code>WizardVm</code> binds to a window, and <code>WizardStepVm</code>binds to a content panel inside the window. I am creating the content control programatically, and adding it to the WizardView like this:</p>
  
  <pre><code>// in the "DataContextChanged" handler for the WizardView
  var bn = new Binding("CurrentStep");
  bn.Mode = BindingMode.OneWay;
  
  var contentControl = new ContentControl();
  contentControl.SetBinding(ContentControl.ContentProperty, bn);
  WizardViewStackPanel.Children.Add(contentControl);
  </code></pre>
  
  <p>This renders correctly when the WizardView is initially created. However, if <code>CurrentStep</code> changes, the view does not update to reflect this. CurrentStep changes, but ContentControl continues to display the original WizardStepVm. Also, the old WizardStepVm continues to exist in memory, and its string properties can still be changed (from the view).</p>
  
  <p>Why is this? What do I have to do so that the content control changes to reflect changes in the ViewModel that it is bound to?</p>
  
  <p>(There is actually a good reason for doing this programatically. However, xaml solutions are also appreciated.)</p>