WPF 中的 ListBox、VirtualizingStackPanel 和平滑滚动

编程入门 行业动态 更新时间:2024-10-28 17:29:45
本文介绍了WPF 中的 ListBox、VirtualizingStackPanel 和平滑滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ListBox,它可能有许多行模板化数据库记录,包括一个 Image,绑定到一个 ObservableCollection.有时,该系列可能包含数千件物品.

I have a ListBox that may have many rows of templated DB records, including an Image, bound to an ObservableCollection<MyItem>. Sometimes the collection could hold thousands of items.

性能很棒,但滚动是默认的跳跃行为.我希望它能够平滑滚动,所以我取消选中 ScrollViewer.CanContentScroll.

The performance is great, but the scrolling is the default jumpy behavior. I would like it to have smooth scrolling, so I unchecked ScrollViewer.CanContentScroll.

现在我有流畅的滚动,但性能很糟糕:数据在单独的线程中检索,线程很快完成,但结果显示在ListBox.我认为这是因为取消选中 ScrollViewer.CanContentScroll 将底层 VirtualizingStackPanel 更改为常规的 StackPanel,因此它在显示之前加载整个集合结果.

Now I have smooth scrolling, but the performance is horrendous: the data is retrieved in a separate thread, and the thread finishes quickly, but it takes 10-20 seconds for the results to show in the ListBox. I assume that this is because unchecking ScrollViewer.CanContentScroll changes the underlying VirtualizingStackPanel to a regular StackPanel and so it is loading the entire collection before displaying the results.

所以我的问题是:如何在不牺牲 VirtualizingStackPanel 行为和性能的情况下保持平滑滚动?

So my question is this: how do I retain the the smooth scrolling without sacrificing the VirtualizingStackPanel behavior and performance?

推荐答案

当您取消选中 CanContentScroll 时,您失去虚拟化.答案确实令人沮丧:目前还没有现成的解决方案:(.

When you uncheck CanContentScroll, you lose virtualization. And the answer is really frustrating: For now there is no out-of-the-box solution :(.

PS:这不是这里的第一篇帖子,问这个问题.

PS: This is not the first post here, asking this very question.

这篇关于WPF 中的 ListBox、VirtualizingStackPanel 和平滑滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-30 02:07:01,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:平滑   WPF   ListBox   VirtualizingStackPanel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!