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

RadTreeview with MVVM and dynamic children

3 Answers 432 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
heavywoody
Top achievements
Rank 1
heavywoody asked on 19 Dec 2010, 10:40 PM
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:

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

   

3 Answers, 1 is accepted

Sort by
-1
Tina Stancheva
Telerik team
answered on 22 Dec 2010, 05:34 PM
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.

Regards,
Tina Stancheva
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Tom
Top achievements
Rank 1
answered on 12 Jan 2011, 05:11 PM
I found this artivle by Josh Smith:

http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx

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

Tom
0
Tina Stancheva
Telerik team
answered on 17 Jan 2011, 03:03 PM
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>>
Tags
TreeView
Asked by
heavywoody
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Tom
Top achievements
Rank 1
Share this question
or