I'm trying to implement a virtualizing collection for hierarchical controls similar to the one for regular controls presented in this article.
The solution presented in the article relies heavily on the following behavior (from the article):
When an
ItemsControl
is bound to anIList
implementation, rather than anIEnumerable
implementation, it will not enumerate the entire list, and instead only accesses the items required for display. It uses theCount
property to determine the size of the collection, presumably to set the scroll extents. It will then iterate through the onscreen items using the list indexer. Thus, it is possible to create anIList
that can report to have a large number of items, and yet only actually retrieve the items when required.
I found that while ListBox
has this behavior, TreeView
(which is also an ItemsControl
) doesn't behave like this, and all the items are always requested regardless of whether or not they're displayed on the screen.
So, is this a behavior specific just for ListBox
and not for every ItemsControl
or is it a bug in WPF's TreeView
?
I've also been unable to find any mention of this behavior on MSDN, so if anyone finds it documented anywhere I'd love to know about it.