ListBox Grouping and Virtualization

Ensure the panels discover each other in time for layout.

We need to ensure the panels learn about each other before the very first layout pass, or virtualization will go awry. Here’s a summary of how to do it:

groupingpanelinitialization.png

In your INestedPanel, override OnInitialized() and walk the visual tree, using the VisualTreeHelper class, to find the IOuterPanel instance and store it off. We do this here because when it’s been initialized, the IOuterPanel should already be constructed, and because OnInitialized() occurs before the first layout pass, where we will need to get IOuterPanel.EstimatedViewport to calculate which items need to be generated for display on screen.

Next, have the nested panel call IOuterPanel.AddNestedPanel(). The grouping panel should then add the nested panel to a collection of INestedPanel references that it maintains. Remember, when you have grouping, you could have multiple GroupingItem objects that each wrap a separate instance of your ListBox.ItemsPanel. By maintaining a collection of the nested panels, the grouping panel can notify each one every time the scroll offsets change.

Explore posts in the same categories: WPF

Pages: 1 2 3 4 5 6 7

Tags: , , , , ,

You can comment below, or link to this permanent URL from your own site.

One Comment on “ListBox Grouping and Virtualization”

  1. Luke Says:

    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.


Comment:

You must be logged in to post a comment.