How to bind this data to a TreeView?

2 posts, 0 answers
  1. Manfred
    Manfred avatar
    54 posts
    Member since:
    Jan 2011

    Posted 16 Mar 2011 Link to this post

    Hi there,

    I have the following structure of data:
    public class Entry
      public string Name;
      public string Descrption;
      public bool IsDirectory;
      public string PathToFile;
      public List<Entry> Entries;
    I got a List<Entries> which contains several Entries which contains also List<Entries>.
    This is to show a folder structure and the files in it to create links for downloads.
    How can I bind this to a TreeView to visualize this data and if it is a file to create it as a link?

    Best Regards
  2. Petar Mladenov
    Petar Mladenov avatar
    2992 posts

    Posted 19 Mar 2011 Link to this post

    Hi Manfred,

    I prepared a sample project for you that shows a possible approach to your requirements. Firs of all , it is better to bind the RadTreeView with ObservableCollection, since they inherit from INotifyPropertyChanged and INotifyCollectionChanged and every change in the ViewModel reflects the UI immediately. I used HierarChicalDataTemplate for the Folders (which have children) and DataTemplate for the Files and ItemTemplateSelector. When the RadTreeViewItem is generated , the SelectTemplate() of the TemplateSelecor fires and the business Object (Entry) is passes in the "item" argument. Then by checking the IsDiretory, the correct template is chosen. Please examine the projet and let us know if it satisfies you.

    All the best,
    Petar Mladenov
    the Telerik team
Back to Top