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 st开发者_Python百科atements 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 ?
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
精彩评论