我创建了一个包装器来扩展 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
}
在尝试将列表中的项目绑定(bind)到 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.
当我替换我的 ModelCollection<TModel> 时没有抛出异常与常规 ObservableCollection<T> .
我的意图是允许对单元格进行编辑。我的包装器上是否缺少接口(interface)?
请您参考如下方法:
我能够通过显式实现 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
}
