Hello together,
I am trying to bind my class HierarchicLabel to a treeview. The children are hosted in the Children property.
public class HierarchicLabel : INotifyPropertyChanged { // Constructors ... string _name; public string Name { get { return _name; } private set { _name = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Name")); } } List<HierarchicLabel> _children = null; internal List<HierarchicLabel> Children { get { return _children; } set { _children = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Children")); } } // .... more class stuff
My Binding to the treeview's ItemsSource is in code setting a List<HierarchicLabel> with the "top" instances of my class holding the rest of the items as children. Therefore, I used a HierarchicalDataTemplate:
<HierarchicalDataTemplate x:Key="HeadingTemplate" ItemsSource="{Binding Children}"><TextBlock Text="{Binding Name}"/></HierarchicalDataTemplate>
My TreeView looks like this:
<TreeView HorizontalContentAlignment="Stretch" x:Name="references" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemContainerStyle="{StaticResource TreeViewItemStyle1}" Style="{DynamicResource TreeViewWord}" ItemTemplate="{StaticResource HeadingTemplate}" Background="x:Null}" AllowDrop="True" DragLeave="references_DragLeave"></TreeView>
When I bind my data, I expect an output e.g. like this:
1. Title 1
> 1.1. Subtitle 1
> 1.2. Subtitle 2
> 1.2.1. SubSubTitle 1
2. Title 2
etc...
Here is my problem:
My TreeView only displays the first level (so like 1. Title 1, 2. Title 2). I cannot understand why. I read multiple examples binding data with a hierarchicaldatatemplate like this and it was said it worked fine, but it does not work for me. If this helps,
I am using .NET 4.5. I also deleted all styles and templates from the treeview. So please can someone give me a hint, what I am doing wrong?
Thank you for your help.