Wrapped ObservableCollection<T> throwing `'EditItem' is not allowed for this view` when bound to a WPF DataGrid
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">
<DataGri开发者_Go百科d.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?
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
}
精彩评论