RadTreeview with MVVM and dynamic children

4 posts, 0 answers
  1. heavywoody
    heavywoody avatar
    81 posts
    Member since:
    Oct 2009

    Posted 19 Dec 2010 Link to this post

    I am porting an existing WPF application to MVVM pattern and I am using the RadTreeView.  I am dynamically populating the Items collection at runtime of the RadTreeViewItem depending on whether a user has selected a Category node or a Object node. 

    In a MVVM pattern, I am unsure of how to do this while preserving the state of the Treeview (selected, what is expanded).   So what would I do in the ViewModel and View to have this work?  Would I have to create a class that would emulate the Items collection? How do I preserve the state?

    So I might have something like this:

       --- AFC West (Category)
       --- AFC South (Category)
       ------ Colts (Object)
       ----------QBs (Category)
       -------------Peyton Manning  (Object)
       -------------Curtis Painter (Object)

  2. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 22 Dec 2010 Link to this post

    Hello Christian Loepp,

    You can bind the RadTreeView to a hierarchical data illustrating the described hierarchy and use ContainerBindingCollection to bind the IsExpanded and IsSelected properties of the RadTreeViewItem. You can find more info in this article. It should help you get started. Still, if you need more info, please let us know.

    Tina Stancheva
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for WPF
  3. Tom
    Tom avatar
    50 posts
    Member since:
    Oct 2010

    Posted 12 Jan 2011 Link to this post

    I found this artivle by Josh Smith:


    To be very useful. Although it refers to the standard WPF TreeView, it can also be applied equally well to the Telerik one.

  4. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 17 Jan 2011 Link to this post

    Hello Tom,

    Thank you for your input. I just wanted to let you know that the RadTreeView control implements a LoadOnDemand logic out-of-the-box. You can examine it in the RadTreeView demos here.

    Also, this is an article describing how to bind the RadTreeView control to a hierarchical data and use style binding.

    I hope this will also be useful to the community.

    All the best,
    Tina Stancheva
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top