1

I created a wrapper to extend an ObservableCollection<T>

[Serializable]
public abstract class ModelCollection<TModel> : ModelCollectionBase,
    IList<TModel>, INotifyCollectionChanged, INotifyPropertyChanged
    where TModel : ModelBase<TModel>
{
    private ObservableCollection<TModel> wrappedCollection = new ObservableCollection<TModel>();

    // wrapper implementation goes here
}

I thought it was working fine until I attempted to bind items from a list to a DataGrid.

<DataGrid ItemsSource="{Binding /Orders}" AutoGenerateColumns="False">
    <DataGrid.Columns>
    <DataGridTextColumn Header="Order Id" Binding="{Binding OrderId}" />
        <DataGridTextColumn Header="Date Time" Width="125" Binding="{Binding DateTime}" />
        <DataGridTextColumn Header="Notes" Width="125" Binding="{Binding Notes}" />
        <DataGridTextColumn Header="Cost" Width="75" Binding="{Binding Cost}" />
    </DataGrid.Columns>
</DataGrid>

The items appear in the grid, but double clicking a cell throws 'EditItem' is not allowed for this view.

The exception isn't thrown when I replace my ModelCollection<TModel> with a regular ObservableCollection<T>.

My intent is to allow editing on the cells. Am I missing an interface on my wrapper?

mbursill
  • 2,229
  • 1
  • 27
  • 39

1 Answers1

4

I was able to fix this by explicitly implementing IList

[Serializable]
public abstract class ModelCollection<TModel> : ModelCollectionBase,
    IList<TModel>, IList, INotifyCollectionChanged, INotifyPropertyChanged
    where TModel : ModelBase<TModel>
{
    private ObservableCollection<TModel> wrappedCollection = new ObservableCollection<TModel>();

    // wrapper implementation goes here
}
mbursill
  • 2,229
  • 1
  • 27
  • 39