包装的 ObservableCollection抛出“EditItem”绑定到 WPF DataGrid 时不允许此视图`
我创建了一个包装器来扩展 ObservableCollection
[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”。
当我替换ModelCollection
时,不会引发异常> 带有常规的 ObservableCollection
。
我的目的是允许对单元格进行编辑。我的包装上是否缺少接口?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够通过显式实现
IList
来解决这个问题I was able to fix this by explicitly implementing
IList