Why BindingSource component cannot see inherited p

2019-08-09 12:27发布

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.

2条回答
叼着烟拽天下
2楼-- · 2019-08-09 12:31

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?

查看更多
混吃等死
3楼-- · 2019-08-09 12:41

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

查看更多
登录 后发表回答