Why BindingSource component cannot see inherited properties?

爱⌒轻易说出口 提交于 2019-12-24 06:26:06

问题


I have defined classes:

public class Parent : IParent
{
    public string ParentText
    {
        get { return "ParentText"; }
    }
}

public interface IParent
{
    string ParentText { get;}
}

public class Child : Parent, IChild
{
    public string ChildText
    {
        get { return "ChildText"; }
    }
}

public interface IChild : IParent
{
    string ChildText { get;}
}

When I try to bind control to IChild instance, I can do this for ChildText property, but not for ParentText property. if I try to bind to Child instance, both properties are bindable. Why databinding mechanism does not see properties inherited from other interfaces?

EDIT: SharePoint Newbie is right: databindings work when defined by hand in code. However, I tried to define databindings in designer using BindingSource component. When you add object source to project and point it to IChild interface, only ChildText is visible to define bindings.

I updated title of question to better reflect my problem.


回答1:


Not totally sure about this, but here goes:

Because IChild only inherits from IParent, it cannot see the implementation (i.e. the get accessor) of ParentText, because that exists in Parent, not IParent. So, binding to IChild does not inherit the ParentText property.

In fact, I'm not sure why you are binding to an interface at all. What can you accomplish binding to IChild that you cannot binding to Child?




回答2:


I think, there is a bug in framework which causes described issue. Here is relevant connect issue:

https://connect.microsoft.com/VisualStudio/feedback/details/431273/interface-inheritance-bug



来源:https://stackoverflow.com/questions/1165824/why-bindingsource-component-cannot-see-inherited-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!