i need to bind recursive child nodes for a treeview in wpf .But i really dunno how to make it work .Here is what i have found
ObservableCollection<Animal> animals = new ObservableCollection<Animal>();
animals.Add(new Animal("California Newt"));
animals.Add(new Animal("Tomato Frog"));
animals.Add(new Animal("Green Tree Frog"));
animals.Add(new Animal("Frog"));
AnimalCategories.Add(new AnimalCategory("Amphibians", animals));
animals = new ObservableCollection<Animal>();
animals.Add(new Animal("Golden Silk Spider"));
animals.Add(new Animal("Black Widow Spider"));
AnimalCategories.Add(new AnimalCategory("Spiders", animals))
List that need to be binded on the treeview and here is the structure for it
AnimalCategory Class:
Class AnimalCategory
Private _category As String
Public Property Category As String
Get
Return _category
End Get
Set(ByVal value As String)
_category = value
End Set
End Property
Private _animals As ObservableCollection(Of Animal)
Public ReadOnly Property Animals() As ObservableCollection(Of Animal)
Get
If _animals Is Nothing Then
_animals = New ObservableCollection(Of Animal)()
End If
Return _animals
End Get
End Property
Public Sub New()
End Sub
Public Sub New(category As String, animals As ObservableCollection(Of Animal))
_category = category
_animals = animals
End Sub
End Class
Animal Class:
Class Animal
Private _name As String
Public Property Name As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(name As String)
_name = name
End Sub
End Class
and my xaml code is..!
<TreeView x:Name="radTreeView" Background="#4E4E4E" x:FieldModifier="public" ItemsSource="{x:Static local:cntlWPFMMTreeView.AnimalCategories}"
ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible">
<telerik:RadTreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Animals}">
<TextBlock Text="{Binding Category}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</telerik:RadTreeView.ItemTemplate>
</TreeView>
Using the above code i can bind one level of parent child hiereachy like below,
Buit i need to get bind something like many level of hierarchy like below dynamically
How to do it in WPF ..?

