TreeView and binding my class

2 posts, 0 answers
  1. Sharp
    Sharp avatar
    27 posts
    Member since:
    Feb 2011

    Posted 19 Apr 2011 Link to this post

    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" >
                                <TextBlock Text="{Binding Name}"/>       
     But I see only root element.
  2. Petar Mladenov
    Petar Mladenov avatar
    2991 posts

    Posted 20 Apr 2011 Link to this post

    Hi sharp,

    You have to set the ItemsSource of the HierarchicalDataTemplate like so:
                            <telerik:HierarchicalDataTemplate ItemsSource={Binding userList}>
                                <TextBlock Text="{Binding Name}"/>        
    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
Back to Top