title: WPF MVVM model in multiple views/view models
body: <p>As a learning exercise I'm trying to build a basic WPF app that makes use of the MVVM pattern that shows a list of objects (lets just use customers for simplicity) in a main tab and then allowing the user to edit customers by opening another tab with some sort of edit view. What I'm stuck on is how to go about communicating changes between the views if I want to make use of deferred saving. I've seen some stuff about using a MessageBus but I've also seen a lot about how that's an anti-pattern in MVVM. This is the code I've come up with so far</p>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public class Customer
  {
      public string Name {get; set;}
  }
  </code></pre>
  
  <p><strong>Customer View Model</strong></p>
  
  <pre><code>public class CustomerViewModel
  {
      public string Name 
      {
          get { return _model.Name; }
          set {_model.Name = value; RaisePropertyChanged(); }
      }
  
      public void Save()
      {
          //Save the model to a DB/whatever
      }
  
      private Customer _model;
  }
  </code></pre>
  
  <p><strong>Edit View Model</strong></p>
  
  <pre><code>public class EditCustomerViewModel
  {
      public string Name 
      {
          get { return _name; }
          set {_name = value; RaisePropertyChanged(); }
      }
  
      public void Save()
      {
          _model.Name = _name;
          _model.Save();
      }
  
      private string _name;
  
      private CustomerViewModel _model;
  }
  </code></pre>
  
  <p><strong>List View Model</strong></p>
  
  <pre><code>public class CustomerListViewModel
  {
      public ObservableCollection&lt;CustomerViewModel&gt; Customers
      {
          get { return _customers; }
      }
  
      private ObservableCollection&lt;CustomerViewModel&gt; _customers;
  }
  </code></pre>
  
  <p>The benefit of this code is that to edit a customer I create an edit view model that has a reference to the same view model this list is using so when changes are saved they show up in the list. The downside is I have to repeat a lot of code in the edit view. Not a problem when there's a few properties but definitely an issue with a lot. As well I can't imagine this scales when connected to a DB with many customers as I'd have to load all the customers into the list just to edit one (though maybe there's other solutions to this).</p>
  
  <p>Is this the best way to approach a problem like this or is there a practice in MVVM that handles this kind of issue?</p>