title: ViewModel contains collection of another ViewModel
body: <p>In all tutorial about MVVM I read that <code>View</code> should not know about <code>Model</code>, hence <code>ViewModel</code> layer is introduced. </p>
  
  <p>If so in situation like: we have <code>Shelf</code> which contains <code>Pack</code>:</p>
  
  <pre><code>namespace Storage.Model
  {
      class Pack
      {
          public string Name { get; set; }
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;UserControl x:Class="Storage.View.Shelf" ... &gt;
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="20" /&gt;
              &lt;RowDefinition Height="50" /&gt;
              &lt;RowDefinition Height="*" /&gt;
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;TextBlock Grid.Row="0" Text="{Binding Path=Name}"/&gt;
          &lt;TextBlock Grid.Row="1" Text="{Binding Path=Capability}"/&gt;
          &lt;ItemsControl Grid.Row="2" ItemsSource="{Binding Path=Packs}"&gt;
              &lt;ItemsControl.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;Border&gt;
                          &lt;TextBlock Text="{Binding Name}" /&gt; 
                      &lt;/Border&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ItemsControl.ItemTemplate&gt;
          &lt;/ItemsControl&gt;
  
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>// DataContext for Shelf 
  namespace Storage.ViewModel
  {
      public class ShelfViewModel
      {
          public string Name { get; set; }
          public string Capability { get; set; }
          // It's okay that ViewModel contains collection of another ViewModel?
          public ObservableCollection&lt;PackViewModel&gt; Packs { get; set; } 
      }
  }
  </code></pre>
  
  
  
  <pre><code>// DataContext for Pack
  namespace Storage.ViewModel
  {
      class PackViewModel
      {
          private Pack pack;
          public string Name 
          {
             get{ return pack.Name; }
             set{ ... }
          }
  
          public PackViewModel(int id)
          {
              // How to populate reference to Pack instance?
              pack = (new PackRepository()).getById(id) 
          }
      }
  }
  </code></pre>
  
  <p>Like I mention in code comment above, it okey that one ViewModel create instances of another ViewModel? I can image case where we have <code>Storage</code>  with collection of <code>Shelf</code>, hence we end up with cascading reference to ModelView: <code>StoreViewModel</code> contains <code>ObservableCollection&lt;ShelfViewModel&gt;</code> which cotains collection of <code>ObservableCollection&lt;PackViewModel&gt;</code>.</p>
  
  <p>Another problem with arise with that solution is that how to populate newly introduced <code>PackViewModel</code> with reference to <code>Pack</code> class? We must somehow pass unique identifier to <code>PackViewModel</code> instance.</p>
  
  <p>I don't want hide that this question is related to my other question <a href="https://stackoverflow.com/questions/48141143/shoud-view-layer-know-about-model-classes-entities">Shoud view layer know about model classes (entities)?</a></p>