This is a migrated thread and some comments may be shown as answers.

TreeView and binding my class

1 Answer 32 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Artem
Top achievements
Rank 1
Artem asked on 19 Apr 2011, 06:32 AM
Hi.
I have class
public class User
{
public int Id {get; set;}
public string Name{get;set;}
public string phone{get;set;}
public List<User> userList {get; set;}
}
How can I bind list with this type data to treeView.
I've try  this:
<telerik:RadTreeView x:Name="userTree" >
                    <telerik:RadTreeView.ItemTemplate>
                        <telerik:HierarchicalDataTemplate>
                            <TextBlock Text="{Binding Name}"/>       
                        </telerik:HierarchicalDataTemplate>
                    </telerik:RadTreeView.ItemTemplate>
 
                </telerik:RadTreeView>
 But I see only root element.

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 20 Apr 2011, 09:01 AM
Hi sharp,

You have to set the ItemsSource of the HierarchicalDataTemplate like so:
<telerik:RadTreeView.ItemTemplate>
                        <telerik:HierarchicalDataTemplate ItemsSource={Binding userList}>
                            <TextBlock Text="{Binding Name}"/>        
                        </telerik:HierarchicalDataTemplate>
                    </telerik:RadTreeView.ItemTemplate>
You can also check out the attached project and this help article if you need more info. Let us know if this helped you. Additionally, it is better practice to use ObservableCollection instead of List since it inherits from INotifyCollectionChanged and INotifyPropertyChanged and this way every change in the ViewModel will be automatically reflected in the UI.

Kind regards,
Petar Mladenov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
Artem
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or