开发者

How does VirtualizingStackPanel decide when to unload (dispose?) of virtualized controls?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜