Question: I have the collection implementing `IList` 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 `PropertyChanged` event. For now the items returned by the collection looks like this:

```cs
public class VirtualCollectionItem 
{
    // actual entity
    public object Item { get; } 

    // some metadata properties
    public bool IsLoading { get; } 
}

```

The problem is that I couldn't realize how to bind such collection to `DataGrid`.
I want somehow set the `DataGrid.ItemsSource` to the collection of `VirtualCollectionItem`, make `DataGrid` show the actual items (in `SelectedItem` too) and leave the possibility to use metadata ( i.e. use `IsLoading` to visualize data loading).
I've tried to set `DataGridRow.Item` binding in `DataGrid.RowStyle` but that haven't worked.

```xml
<DataGrid.RowStyle>
  <Style TargetType="{x:Type DataGridRow}">
    <Setter Property="Item" Value="{Binding Item}" />
    <Style.Triggers>
      <DataTrigger Binding="{Binding IsLoading}" Value="True">
        <DataTrigger.Setters>
          <Setter Property="Background" Value="Gray" />
        </DataTrigger.Setters>
      </DataTrigger>
    </Style.Triggers>
  </Style>
</DataGrid.RowStyle>

```

Another option is to flatten `VirtualCollectionItem` properties into `VirtualCollection` itself:

```cs
class VirtualCollection
{
    // ...

    // wrapper around VirtualCollectionItem
    public IList<object> Items { get; }

    public IList<bool> IsLoadingItems { get; } 

    // ...
}

```

and use these properties in `DataGrid`, but I have not realize how to make this working.

Answer: 
I decided to wrap the DataGrid with the ViewModel:

```cs
public class DataGridAsyncViewModel : Notifier
{
  public VirtualCollection ItemsProvider { get; }

  private VirtualCollectionItem _selectedGridItem;

  public VirtualCollectionItem SelectedGridItem
  {
    get { return _selectedGridItem; }
    set { Set(ref _selectedGridItem, value); }
  }

  public object SelectedItem => SelectedGridItem?.IsLoading == false ? SelectedGridItem?.Item : null;

  public DataGridAsyncViewModel([NotNull] VirtualCollection itemsProvider)
  {
    if (itemsProvider == null) throw new ArgumentNullException(nameof(itemsProvider));
    ItemsProvider = itemsProvider;
  }
}

```

And bound it to the DataGrid:

```xml
<DataGrid DataContext="{Binding DataGridViewModel}" 
          SelectedItem="{Binding SelectedGridItem}" 
          ItemsSource="{Binding ItemsProvider}" >
  <DataGrid.RowStyle>
    <Style TargetType="{x:Type DataGridRow}">
      <Style.Triggers>
        <DataTrigger Binding="{Binding IsLoading}" Value="True">
          <Setter Property="Background" Value="LightGray" />
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </DataGrid.RowStyle>
  <DataGrid.Columns>
    <DataGridTextColumn Header="..." Binding="{Binding Item.SomeValue}" />
  </DataGrid.Columns>
</DataGrid>

```
You can bind the VirtualCollection directly to the DataGrid.ItemsSource property. Then bind the SelectedItem property too:

```
<DataGrid ItemsSource="{Binding MyVirtualCollectionList}" SelectedItem={Binding SelectedItem, Mode=TwoWay} />

```

Then the ViewModel:

```
public class MyViewModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

    private VirtualCollection _myVirtualCollectionList;

    public VirtualCollection MyVirtualCollectionList
    {
        get { return _myVirtualCollectionList; }
        set
        {
            _myVirtualCollectionList = value;
            OnPropertyChanged();
        }
    }

    private VirtualCollectionItem _selectedItem;

    public VirtualCollectionItem SelectedItem
    {
        get { return _selectedItem; }
        set
        {
            _selectedItem = value;
            OnPropertyChanged();
        }
    }
}

```

You have to fire the OnPropertyChanged event after loading the list and you have to do it from the MyViewModel object (Which I think you do not do)! You could use an ObservableCollection too (you can extend it). Then you do not need the OnPropertyChange event. Adding/removing items from the collection automatically notifies the UI.

The SelectedItem is working independently to the list. In the DataTemplate for a row you will use {Binding IsLoading} and {Binding Item.SomeProperty}.