3

I'm working with an ItemsControl using a VirtualizingStackPanel in its ControlTemplate. I've got the virtualization working, to some extent. I've put debugging statements in the Loaded and Unloaded event handlers for the controls in my DataTemplate for the items, but they don't get unloaded immediately after the controls go out of view. Is there any way to force this behaviour ?

Alex Marshall
  • 10,162
  • 15
  • 72
  • 117

1 Answers1

2

You might have some luck setting the VirtualizationMode to Recycled. There are comments in the source code for VirtualizingStackPanel.cs that indicate Recycled mode immediately cleans up renderers (instead of doing it 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, you can find the full source for VirtualizingStackPanel here:

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

zpinter
  • 2,232
  • 2
  • 23
  • 29
  • Thanks a lot for the link to the sources, I have been always just hunting around on the web for scraps of it, completely oblivious that I could just get the whole lot from Microsoft! – dain Jan 31 '12 at 11:08