包装的ObservableCollection T当绑定到WPF DataGrid时,不允许对此视图抛出`EditItem' [英] Wrapped ObservableCollection<T> throwing `'EditItem' is not allowed for this view` when bound to a WPF DataGrid
问题描述
我创建了一个包装器来扩展ObservableCollection<T>
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
}
在我尝试将列表中的项目绑定到DataGrid之前,我一直认为它工作正常.
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>
项目显示在网格中,但是双击一个单元格会抛出'EditItem' is not allowed for this view.
The items appear in the grid, but double clicking a cell throws 'EditItem' is not allowed for this view.
当我用常规的ObservableCollection<T>
替换我的ModelCollection<TModel>
时,不会引发异常.
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?
推荐答案
我能够通过显式实现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
}
这篇关于包装的ObservableCollection T当绑定到WPF DataGrid时,不允许对此视图抛出`EditItem'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!