views:

221

answers:

2

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.

A: 

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?

Matthew Jones
I have many implementations of IChild. My view (Form) does not know exact implementation, so I need to work with interface.
Przemaas
Matthew, the same logic you can apply to ChildText property, but ChildText is visible to databinding
Przemaas
A: 

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

Przemaas