title: WPF DataGrid bind to ItemsSource items property
body: <p>I have the collection implementing <code>IList</code> which asynchronously loads data from server. When the collection is accessed by index it returns a stub object and starts the data request in background. After the request has finished collection refreshes inner state and invokes <code>PropertyChanged</code> event. For now the items returned by the collection looks like this:</p>
  
  
  
  <pre class="lang-cs prettyprint-override"><code>public class VirtualCollectionItem 
  {
      // actual entity
      public object Item { get; } 
  
      // some metadata properties
      public bool IsLoading { get; } 
  }
  </code></pre>
  
  <p>The problem is that I couldn't realize how to bind such collection to <code>DataGrid</code>.
  I want somehow set the <code>DataGrid.ItemsSource</code> to the collection of <code>VirtualCollectionItem</code>, make <code>DataGrid</code> show the actual items (in <code>SelectedItem</code> too) and leave the possibility to use metadata ( i.e. use <code>IsLoading</code> to visualize data loading).
  I've tried to set <code>DataGridRow.Item</code> binding in <code>DataGrid.RowStyle</code> but that haven't worked.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;DataGrid.RowStyle&gt;
    &lt;Style TargetType="{x:Type DataGridRow}"&gt;
      &lt;Setter Property="Item" Value="{Binding Item}" /&gt;
      &lt;Style.Triggers&gt;
        &lt;DataTrigger Binding="{Binding IsLoading}" Value="True"&gt;
          &lt;DataTrigger.Setters&gt;
            &lt;Setter Property="Background" Value="Gray" /&gt;
          &lt;/DataTrigger.Setters&gt;
        &lt;/DataTrigger&gt;
      &lt;/Style.Triggers&gt;
    &lt;/Style&gt;
  &lt;/DataGrid.RowStyle&gt;
  </code></pre>
  
  <p>Another option is to flatten <code>VirtualCollectionItem</code> properties into <code>VirtualCollection</code> itself:</p>
  
  <pre class="lang-cs prettyprint-override"><code>class VirtualCollection
  {
      // ...
  
      // wrapper around VirtualCollectionItem
      public IList&lt;object&gt; Items { get; }
  
      public IList&lt;bool&gt; IsLoadingItems { get; } 
  
      // ...
  }
  </code></pre>
  
  <p>and use these properties in <code>DataGrid</code>, but I have not realize how to make this working.</p>