此视图不允许使用“EditItem” - 数据绑定问题 [英] 'EditItem' is not allowed for this view - databinding issue

查看:2068
本文介绍了此视图不允许使用“EditItem” - 数据绑定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用一个cutom列表在WPF上进行数据绑定。我的自定义列表类包含List类型的私有数据列表。我不能公开这个列表,但是索引器被暴露以进行搜索和获取单个项目。
我的自定义类看起来像这样:

I am trying to do data binding in WPF on data grid using a cutom list. My custom list class contains a private data list of type List. I can not expose this list however the indexers are exposed for seeting and getting individual items. My custom class looks like this:

public abstract class TestElementList<T> : IEnumerable
        where T : class
{
    protected List<T> Data { get; set; }
    public virtual T Get(int index)
    {
        T item = Data[index];
        return item;
    }

    public virtual void Set(int index, T item)
    {
         Data[index] = item;
    }
...
}

数据绑定但是当我尝试编辑它,我得到'EditItem'不允许这个视图。错误。在网络上进行广泛搜索时,我发现我可能需要实现IEditableCollectionView界面。
任何人都可以帮助我指出如何实现这个界面,或者任何其他更好的方式在自定义列表中进行数据绑定。

The data is binded but when I try to edit it, i get "'EditItem' is not allowed for this view." Error. On doing extensive searching over web, I found that i might need to implement IEditableCollectionView interface also. Can anybody please help me to either give pointers on how to implement this interface or any suggest any other better way to do databinding on custom list.

谢谢

推荐答案

虽然我不完全明白您的要求,您认为使用ObservableCollection可以解决您的问题吗? >

though I am not fully understand your requirement, do you think using an ObservableCollection will solve your issue?

public abstract class TestElementList<T> : ObservableCollection<T>
    where T : class
 {
   public virtual T Get(int index)
   {
     T item = this[index];
     return item;
   }

   public virtual void Set(int index, T item)
   {
     this[index] = item;
   }
 ...
}

这篇关于此视图不允许使用“EditItem” - 数据绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆