ListBox Grouping and Virtualization
IOuterPanel and INestedPanel
Because we will have two panels communicate with each other, I defined two interfaces, IOuterPanel and INestedPanel (sorry about the bad formatting):
public interface IOuterPanel
{
Size EstimatedViewport { get; }
double VerticalOffset { get; }
ScrollViewer ScrollOwner { get; }
void AddNestedPanel( INestedScrollingPanel nestedPanel );
}
Our grouping panel will implement this interface. The EstimatedViewport property what the inner panel will query during its layout pass to get a fairly accurate value of what the visible area is. Likewise, the nested panel(s) will use VerticalOffset to aid in figuring out which children to realize during each layout pass. We expose the ScrollOwner for the nested panel because it [the outer panel] is the one communicating with the ScrollViewer.
Finally, AddNestedPanel() will be called by any inner panels to make themselves known to the grouping panel. The grouping panel will maintain a collection of nested panels. I will elaborate on this later.
interface INestedPanel : IScrollInfo
{
IOuterPanel OuterPanel { set; }
}
Our inner, virtualizing panel will implement this interface. It derives from IScrollInfo because we want the outer panel to call the appropriate scrolling methods on it in order to ensure items are realized/unrealized correctly. I defined a property to set the OuterPanel so that this panel can query the outer panel for IOuterPanel.EstimatedViewport and IOuterPanel.VerticalOffset properties as necessary. Additionally, this way the nested panel can tell the grouping panel about itself.
So to sum up how these panels will interact with each other:

This entry was posted on February 22, 2008 at 9:04 pm and is filed under WPF. You can subscribe via RSS 2.0 feed to this post's comments.
Tags: grouping, lazy-loading, ListBox, panel, scrolling, virtualizing
You can comment below, or link to this permanent URL from your own site.
July 9, 2009 at 11:10 am
Great blog post! Can you please provide more details how you reworked your solution to support sorting? I am having trouble with virtualization when grouping is enabled and can’t seem to solve this issue.