title: Nested view model in WPF
body: <p>Still trying to learn MVVM and WPF here.</p>
  
  <p>I'm trying to create a complex view model <code>EditArticleViewModel</code>. It has some code that is repeated for similar controls and so I've moved the repeating code into another class. Then, I've added several instances of that other class into <code>EditArticleViewModel</code>.</p>
  
  <p>I will set an instance of <code>EditArticleViewModel</code> as my window's <code>DataContext</code>. And I will bind to things like <code>Categories.Items</code> and <code>Subcategories.SelectedItem</code>.</p>
  
  <pre><code>public class CategoryView
  {
      public ObservableCollection&lt;object&gt; Items { /* */ }
      public object SelectedItem { /* ... */ }
  }
  
  public class SubcategoryView
  {
      public ObservableCollection&lt;object&gt; Items { /* */ }
      public object SelectedItem { /* ... */ }
  }
  
  public class EditArticleViewModel : INotifyPropertyChanged
  {
      public CategoryView Categories { get; private set; }
      public SubcategoryView Subcategories { get; private set; }
  
      public EditArticleViewModel()
      {
          Categories = new CategoryView();
          SubcategoryView Subcategories new SubcategoryView();
      }
  
      // Additional properties and methods here
  
  }
  </code></pre>
  
  <p>As you can see, my <code>EditArticleViewModel</code> class implements <code>INotifyPropertyChanged</code> so that I can notify the visual elements when something has changed.</p>
  
  <p>My question is about how I notify visual elements about changes within <code>CategoryView</code> and <code>SubcategoryView</code>. Is there a way to notify the window about changes within these classes directly? Or must I raise an event from each class and have <code>EditArticleViewModel</code> handle that event in order to send the appropriate notification?</p>
  
  <p>Any tips appreciated.</p>