wpf treeview binding

Is there any simple tutorial for beginners about treeview binding in WPF?

What should we write in ItemsSource, DataType, ItemTemplate attributes if there's one List of items?

IList<string> items = new List<string>();

XAML code:

<TreeView Name="treeView1">  
    <TreeView.Resources> <!-- what does it mean? -->
        <HierarchicalDataTemplate DataType="???" ItemsSource="{Binding ???}"></HierarchicalDataTemplate>  


To Fully understand how to use the wpf treeview with data binding, I went through the following tutorials in order -

1) A very simple example of treeview binding using recursion


2) Claus Konrads simple example of data binding with the treeview. It's the most straightforward example I have come across and should get any newcomers to wpf up to speed.


3) Mike Hillbergs tutorial shows, in detail, the ins and outs of the treeview, how it compares to other wpf controls, and how to bind data.


Have a look at Josh Smiths excellent tutorial

Treeview is one control in wpf that you have to appoach in a little diffrent manner.It is simple and efficient and at the same time a pain to understand and get in track for a beginer,especially those coming from the windows appliaction backgroud.Please go through the MVVM pattern first and then try to approach the treeview.

The Josh Smith article below is a good place to start.


The trick is that ItemsSource points to the next collection down.

e.g Imagine you have a collection of type A, and each A contains a description and a collection of type B; and each B contains a description and a collection of type C. The binding would look like this:

<TreeView Width="400" ItemsSource="{Binding CollectionOfA}">
        <HierarchicalDataTemplate DataType="{x:Type TypeA}" ItemsSource="{Binding CollectionOfB}">
            <TreeViewItem Header="{Binding TypeADescription}" />
        <HierarchicalDataTemplate DataType="{x:Type TypeB}" ItemsSource="{Binding CollectionOfC}">
            <TreeViewItem Header="{Binding TypeBDescription" />
        <HierarchicalDataTemplate DataType="{x:Type TypeC}">
            <TreeViewItem Header="{Binding TypeC}" />

Need Your Help

akka or similar alternative for golang to support distributed concurrency?

go distributed-computing

I know golang is very good at concurrency with its built-in support, but seems to me they are not distributed, so what would be the framework/library allow us to write producers/consumers applicati...

How to delete from Firebase database

swift firebase firebase-realtime-database

Hi i have followed this tutorial: https://www.youtube.com/watch?v=XIQsQ2injLo