虚拟化后渲染线程仍然很慢
在较高级别上,我的应用程序根据类型将大约 5 个不同的 DataTemplates 应用到一组 ListBoxItems。这些项目布置在画布上的特定 x、y 点处。我在 ListBox 上实现了虚拟化,但它似乎并没有改善完成渲染线程进程所需的时间。 UI 完全加载并可供用户使用仍需要大约 8-12 秒的时间。我认为虚拟化将有助于解决这个问题,但环顾四周后,它似乎只能帮助处理滚动大量数据。我的这个假设是否正确?其他人是否有任何其他改进渲染线程的技巧。这是我遇到的唯一问题,然后我的项目就完成了。感谢堆栈溢出!
At a high level my application is applying about 5 different DataTemplates to a set of ListBoxItems based on their type. These items are laid out on a canvas at specific x, y points. I implemented virtualization on my ListBox and it did not seem to improve the time it takes to complete the rendering thread's processes. It still takes about 8-12 seconds for the UI to be completely loaded and usable by the user. I thought virtualization would help fix this problem but after looking around it looks like it only helps process scrolling large amounts of data. Am I correct in this assumption and does anyone else have any other tips for improving the rendering thread. This is the only problem I am having and then my project is complete. Thanks StackOverflow!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
虚拟化意味着仅创建您可见的项目,然后在滚动时动态销毁/创建新项目。另一种方法是同时为所有项目创建所有 UI 控件。
听起来您对应用程序的其余部分有更大的问题。您是否在后台线程上执行所有加载操作? UI控件树真的很复杂吗?您正在展示 100 或 1,000 件商品吗?
Virtualisation means that only the items you have visible are created, then dynamically destroyed/new items created as you scroll. The alternative is all UI controls are created for all items at once.
It sounds like you have bigger problems with the rest of the app. Do you perform all loading operations on a background thread? Is the UI control tree very complex indeed? Are you displaying 100s or 1,000s of items?
我们在 WPF 的性能方面也遇到了很多麻烦。最好的方法当然是分析您的应用程序。为此,我们使用 ANTS 性能分析器,但任何 .NET 分析器都可以。由于查找 XAML 资源,我们的性能受到了巨大影响。这就是我可以给你的建议:
尝试最小化 XAML 中的所有资源。但不仅如此,还要尽量减少 XAML 文件的数量。您可以尝试的一件事是推迟 DataTemplate 的复杂部分的加载。与在浏览器中加载 JPEG 时发生的情况类似,首先您会看到一个像素化图像,在加载完 JPEG 后该图像会变得更精细。为此,请首先使用更简单的 DataTemplate,然后如果可见,则仅按需或稍后加载复杂的模板。
但如果没有您的具体问题的更多信息,我们只能猜测。 这是我关于类似主题的一个老问题,也许这也会有帮助。
We also had a lot of trouble with performance in WPF. Best way is of course to profile your application. We use ANTS Performance profiler for that, but any .NET profiler will do. We got a huge performance hit, because of the lookup of our XAML Resources. Thats the advice i can give you:
Try to minimize all resources in XAML. But not only that, also try to minimize the amount of XAML files you have. One thing you can try is to defere the loading of complex parts of your DataTemplate. Similiar to what happens when you load a JPEG in a browser, first you will see a pixelated image which will be finer after it finished loading the JPEG. To accomplish that, use a simpler DataTemplate at first and then if this is visible only load the complex template on demand or after a while.
But without more information of your specific problem, we can only guess. This is an old question of mine about a similiar subject, maybe this will help aswell.
是的,ListBox虚拟化就是为了滚动。当 ListBox 中有大量项目时,启用虚拟化将仅渲染可见项目(+一些用于滚动的额外项目),并且滚动 ListBox 会替换已渲染项目中的数据,而不是渲染新项目。
如果您要发布一些代码,也许我们可以帮助您进行一些性能调整
Yes, ListBox virtualization is for scrolling. When you have a large number of items in a ListBox, enabling virtualization will make only the visible items (+ a few extra items for scrolling) render, and scrolling the ListBox replaces the data in the rendered items instead of rendering new items.
If you were to post some code, perhaps we could assist you with some performance tweaks