title: How do I structure MVVM with Collections?
body: <p>I'm having trouble understanding how to apply the MVVM pattern when Lists/Collections are involved.</p>
  
  <p>Say the <code>MainModel</code> has a few properties and methods, as well as a list that contains other <code>DetailModel</code> objects. The <code>DetailModel</code> objects can be added, removed, or re-ordered.</p>
  
  <p>The <code>MainView</code> will show a few controls related the the root model, and have a <code>ListBox</code> populated from the list. Each item will have it's own sub-view via a <code>DetailModelView</code> <code>UserControl</code>.</p>
  
  <p>Finally, there is a <code>MainViewModel</code>. This has properties backed by the <code>MainModel</code>'s properties and methods, bound to the Main View, with change notification keeping everything in sync. (Up to this point, I am comfortable with the pattern - more stating this in case there is something fundamental I am missing...)</p>
  
  <p>When it comes to handling the list, I get confused.  I have come across several examples where the <code>MainViewModel</code> simply exposes the list of <code>DetailModels</code> to the view, and the <code>DetailModelViews</code> are bound directly to the models.  This <em>functions</em>, but is problematic.  It does not consistently following the pattern (no <code>DetailViewModel</code> exists), and it drives me to include some UI-related code in my detail models.  It seems clear to me that the <code>MainViewModel</code> should expose a list of <code>DetailViewModels</code> for the UI to bind, but I am stuck on how to implement such a thing!</p>
  
  <p>How should manage the two lists (<code>DetailModels</code> and <code>DetailViewModels</code>)?  I am really confused as where I initially populate the <code>DetailViewModel</code> list, and how I should handle adding, removing, or changing the order of the items to keep them synchronized!</p>