Binding to base class property

1.7k Views Asked by At

I have classes like this:

public class A : INotifyPropertyChanged
{
    public ObservableCollection<A> Children { get; set; }
}

public class B : A
{
}
public class C : A
{
    public ObservableCollection<A> Children2 { get { return Children; } }
}

And i'm trying to bind them using HierarchicalDataTemplate like this:

<HierarchicalDataTemplate DataType="{x:Type local:B} ItemSource="{Binding Children}">
    <TextBlock Text="foo"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:C} ItemSource="{Binding Children2}">
    <TextBlock Text="bar"/>
</HierarchicalDataTemplate>

Which results in B beeing not expandable (as if nothing was bound) while C works just fine.
How do I bind to base class property without need to expose it again in derived class?

0

There are 0 best solutions below