![](/img/trans.png)
[英]DataGrid edition 'EditItem' is not allowed for this view` when bound to a WPF DataGrid
[英]Wrapped ObservableCollection<T> throwing `'EditItem' is not allowed for this view` when bound to a WPF DataGrid
我创建了一个包装器来扩展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 之前,我认为它工作正常。
<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.
当我用常规ObservableCollection<T>
替换我的ModelCollection<TModel>
时,不会引发异常。
我的意图是允许对单元格进行编辑。 我是否缺少包装器上的接口?
我能够通过显式实现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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.