问题描述
我有一个 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中需要10-20秒的时间代码>.我认为这是因为取消选中
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:关键词]
发布评论