title: Dynamic views in WPF
body: <p>I'm trying to dynamically change <code>UserControl</code> views that are defined in an <code>ObservableCollection</code>.</p>
  
  <pre><code>public class MItem : INotifyPropertyChanged
      {
          private UserControl _mView;
          public UserControl MView
          {
              get { return _mView; }
              set
              {
                  if (_mView != value)
                  {
                      _mView = value;
                      OnPropertyChanged("MView");
                  }
              }
          }
  
  ...
          }
  </code></pre>
  
  <p>In a separate view I have:</p>
  
  <pre><code>ObservableCollection&lt;MItem&gt; _items = new ObservableCollection&lt;MItem&gt;;
  
  _items.Add(new MItem{MView = MyView});
  </code></pre>
  
  <p>Obviously when it comes to create a new object of that view and then assigning it to a child on a Grid comes to be a problem - It'll give me a type error.</p>
  
  <p>I've tried something like:</p>
  
  <pre><code>_items[0].MView = new UserControl(); // I know this wouldn't work
  </code></pre>
  
  <p>My main question is, has anyone tried implementing something like this and how did you get around it?</p>
  
  <p>Thanks</p>