WPF中的ListBox,VirtualizingStackPanel和平滑滚动 [英] ListBox, VirtualizingStackPanel, and Smooth Scrolling in WPF
问题描述
我有一个ListBox
,它可能具有许多行的模板化DB记录,包括绑定到ObservableCollection<MyItem>
的Image
.有时该收藏可以容纳数千个物品.
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
.
现在,我可以流畅地滚动,但是性能太差了:在一个单独的线程中检索数据,该线程很快完成,但是要花10到20秒的时间才能在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?
推荐答案
When you uncheck CanContentScroll, you lose virtualization. And the answer is really frustrating: For now there is no out-of-the-box solution :(.
PS: This is not the first post here, asking this very question.
这篇关于WPF中的ListBox,VirtualizingStackPanel和平滑滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!