How does VirtualizingStackPanel decide when to unload (delete?) Virtualized controls?

I am working with an ItemsControl using VirtualizationStackPanel in a ControlTemplate. Virtualization works for me, to some extent. I set the debug statements in the Loaded and Unloaded event handlers for the controls in the DataTemplate for the elements, but they are not unloaded right after the controls go out of view. Is there any way to force this behavior?

+3
source share
1 answer

You may be lucky that VirtualizationMode has reworked. There are comments in the source code for VirtualizingStackPanel.cs that indicate that Recycled mode immediately clears the renderers (instead of doing this in the background):

    // 
    // Delayed Cleanup is used when the VirtualizationMode is standard (not recycling) and the panel is scrolling and item-based
    // It chooses to defer virtualizing items until there are enough available.  It then cleans them using a background priority dispatcher 
    // work item
    //

Note. Here you can find the full source for VirtualizationStackPanel:

http://referencesource.microsoft.com/netframework.aspx

+2
source

Source: https://habr.com/ru/post/1787744/


All Articles