How to create a HierarchalVirtualizingStackPanel
hi guys,
I would like someone to explain to me why VirtualizingStackPanel does not understand hierarchies?
I want to implement something similar to the VirtualizingStackPanel but it can understand hiererachies... if any one has any comments or some kind of feed back I would highly appreciate it...
The more help the better
Regards
Answers
I would never say it's not worthy... If you're looking for an academic challenge, this would definitely be a good one!
In addition to sizing and positioning its children, a virtualizing panel does two things:
1) It provides scroll information by implementing IScrollInfo.
2) It provides item container generation (both realization and virtualization of its children) by invoking methods of IItemContainerGenerator (on its associated ItemsControl) based on its viewport.
In the case of a virtualized tree view, you can implement a custom VirtualizedTreeView (VTV) panel. This VTV panel will serve as the items host for the TreeView. Of course, each TreeViewItem is also its own items control (or more specifically, its own HeaderedItemsControl). As such, the VTV panel will also be used as the items host for each TreeViewItem in the hierarchy.
If its associated TreeView/TreeViewItem is expanded, a VTV panel will realize its child TreeViewItems.... at least as many as will fit within the available viewport.
The VTV panel will need to implement IScrollInfo, just like other virtualizing panels. But recognize that only the root VTV panel will actively provide scroll functionality. This will be the panel serving as the items host for the TreeView itself. It will be wrapped within a ScrollViewer in the TreeView template.
Normally, virtualizing panels create and remove children based purely on scroll position, but not in this model. Since the root VTV panel is the only one providing scroll information, it will have to serve as the controlling VTV panel for the entire hierarchy. All descendant VTV panels will need to base their realizations and virtualizations on requests passed down from their immediate parent VTV panel.
For example, the root panel recognizes it has a 100x400 area available after accounting for its associated header. It will then realize its first child and pass it this remaining size (perhaps by setting an attached property on the child TreeViewItem). The child VTV panel will then calculate how much space is required for its associated header. Suppose it still has a 100x350 area remaining. If it happens to be an expanded item, it will realize its first child and similarly pass it the remaining size. Thus begins the recursion. It continues until all expanded children are realized or until the available space is exhausted.
Each child will return its size (which includes the size of its expanded children) to its parent. Eventually, the root VTV panel will know the size of its first child branch. It will then know if there is room remaining to begin realizing the next child branch.
Note that this algorithm is essentially the same one used to lay out the nodes of an orthogonal tree graph.
That covers realizing... There will be similar fun for virtualizing the nodes. Definitely a good challenge!
Luckily, its not too difficult to implement routines that flatten hierarchical data, so Bea’s solution is a fairly compelling shortcut. (Of course, it’s not nearly as pure! So I say go for it. I'm looking forward to seeing it in action.
)
Cheers!
P.S. Yes, I'm a big fan of Dwayne's work. I understand that his team is responsible for much of the coolness in 3.5 with respect to perf improvements for media, animation, and graphics. Kudos to all of them!
Hi there,
I implemented my first Virtualizing Tree view... It is not a pure Virtualizing Tree View it is a ListBox that understands hierarchies and basically it flattens them so that it can use Virtualization...
Have a look at it if you have some time
http://marlongrech.wordpress.com/2007/09/27/virtualizing-treeview-aka-treelistbox/If you can please send me your feed back...
Best Regards
All Replies
The UI virtualization that is available through a virtualizing panel (like VirtualizingStackPanel) is enabled because the panel and the ItemContainerGenerator of an ItemsControl can work together to realize only the elements that are visible within a given viewport and then virtualize elements as they go out of the panel's viewport. This is fairly easy to do when you have a single generator doing all of the item generation. But in a hierarchical items control, you have many, many generators and many little panels of elements. So the current virtualizing model breaks down.
But there is a solution to this problem! Bea Costa has just finished a three-part series on improving TreeView perf. If you have not read it yet, you should definitely check out parts one, two and three. She explains how a ListView can be styled to look and behave like a TreeView (and thereby gain the benefits of UI virtualization). And then with a little massaging of the data model, you can add data virtualization to the equation.
I'm working on a project in which we recently implemented this approach to represent hierarchical data in a large-scale, data-driven application. It's very effective!
Hi there,
nice to hear from you....
I already saw bea costa example... It's a good idea but this implies that you have to change your business objects so that you have a flat list!!!!
I was hoping you have a VirtaulizingStackPanel that supports a hierarchy...
do you think it's too complex to do?? do you think it is not worthed??
I really appreaciate your help? I always enjoy having a tech chat with you...
P.S I found this cool threading link , I know you will like it....
http://blogs.msdn.com/dwayneneed/archive/2007/04/26/multithreaded-ui-hostvisual.aspx
RegardsI would never say it's not worthy... If you're looking for an academic challenge, this would definitely be a good one!
In addition to sizing and positioning its children, a virtualizing panel does two things:
1) It provides scroll information by implementing IScrollInfo.
2) It provides item container generation (both realization and virtualization of its children) by invoking methods of IItemContainerGenerator (on its associated ItemsControl) based on its viewport.
In the case of a virtualized tree view, you can implement a custom VirtualizedTreeView (VTV) panel. This VTV panel will serve as the items host for the TreeView. Of course, each TreeViewItem is also its own items control (or more specifically, its own HeaderedItemsControl). As such, the VTV panel will also be used as the items host for each TreeViewItem in the hierarchy.
If its associated TreeView/TreeViewItem is expanded, a VTV panel will realize its child TreeViewItems.... at least as many as will fit within the available viewport.
The VTV panel will need to implement IScrollInfo, just like other virtualizing panels. But recognize that only the root VTV panel will actively provide scroll functionality. This will be the panel serving as the items host for the TreeView itself. It will be wrapped within a ScrollViewer in the TreeView template.
Normally, virtualizing panels create and remove children based purely on scroll position, but not in this model. Since the root VTV panel is the only one providing scroll information, it will have to serve as the controlling VTV panel for the entire hierarchy. All descendant VTV panels will need to base their realizations and virtualizations on requests passed down from their immediate parent VTV panel.
For example, the root panel recognizes it has a 100x400 area available after accounting for its associated header. It will then realize its first child and pass it this remaining size (perhaps by setting an attached property on the child TreeViewItem). The child VTV panel will then calculate how much space is required for its associated header. Suppose it still has a 100x350 area remaining. If it happens to be an expanded item, it will realize its first child and similarly pass it the remaining size. Thus begins the recursion. It continues until all expanded children are realized or until the available space is exhausted.
Each child will return its size (which includes the size of its expanded children) to its parent. Eventually, the root VTV panel will know the size of its first child branch. It will then know if there is room remaining to begin realizing the next child branch.
Note that this algorithm is essentially the same one used to lay out the nodes of an orthogonal tree graph.
That covers realizing... There will be similar fun for virtualizing the nodes. Definitely a good challenge!
Luckily, its not too difficult to implement routines that flatten hierarchical data, so Bea’s solution is a fairly compelling shortcut. (Of course, it’s not nearly as pure! So I say go for it. I'm looking forward to seeing it in action.
)
Cheers!
P.S. Yes, I'm a big fan of Dwayne's work. I understand that his team is responsible for much of the coolness in 3.5 with respect to perf improvements for media, animation, and graphics. Kudos to all of them!
I'll put it in the wish list of the AvalonControlsLibrary
there is a lot of work to be done.....
RegardsHi there,
I implemented my first Virtualizing Tree view... It is not a pure Virtualizing Tree View it is a ListBox that understands hierarchies and basically it flattens them so that it can use Virtualization...
Have a look at it if you have some time
http://marlongrech.wordpress.com/2007/09/27/virtualizing-treeview-aka-treelistbox/If you can please send me your feed back...
Best Regards
Happy birthday and nicely done! I gave it a test drive and it definitely delivers on performance.
Thanks a lot.... hope to have a chat with you in the future....

Hi there,
me again... this weekend I am planning to re write the control because I found a better way which would use more the virtualizationstackpanel features...
this is still experimental but I will keep you informed...
regardshi there,
I updated the TreeListBox.... I basically re wrote the whole thing becuase I had a better idea and in fact it was worthed!! now the treelistbox is much faster and consums much less memory... It uses much more fetures of the VirtualizationStackPanel
Please have a look at it and give me your feed back
http://marlongrech.wordpress.com/2007/10/01/virtualizing-treeview-aka-treelistbox-v20/
Thanks a lot


