VirtualizingStackPanel 如何决定何时卸载(处置?)虚拟化控件?

发布于 2024-10-14 09:00:23 字数 179 浏览 2 评论 0原文

我正在使用 ItemsControl,在其 ControlTemplate 中使用 VirtualizingStackPanel。在某种程度上,我已经实现了虚拟化。我已将调试语句放入项目的 DataTemplate 中控件的 Loaded 和 Unloaded 事件处理程序中,但在控件退出视图后它们不会立即卸载。有什么办法可以强制这种行为吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

指尖微凉心微凉 2024-10-21 09:00:23

您可能会幸运地将 VirtualizationMode 设置为 Recycled。 VirtualizingStackPanel.cs 源代码中的注释表明回收模式会立即清理渲染器(而不是在后台执行):

    // 
    // 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
    //

注意,您可以在此处找到 VirtualizingStackPanel 的完整源代码:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文