why setting ScrollViewer.CanContentScroll to false

2019-01-05 04:01发布

As most WPF developers know, setting ScrollViewer.CanContentScroll to false will disable virtualization; but I'd like to know how it works, because I try to enable virtualization while setting ScrollViewer.CanContentScroll to false.

2条回答
贼婆χ
2楼-- · 2019-01-05 04:44

"ScrollViewer currently allows two scrolling modes: smooth pixel-by-pixel scrolling (CanContentScroll = false) or discrete item-by-item scrolling (CanContentScroll = true). Currently WPF supports UI virtualization only when scrolling by item. Pixel-based scrolling is also called “physical scrolling” and item-based scrolling is also called “logical scrolling”."

Virtualization requires an item-based scrolling so it can keep track of logical units (items) currently in view... Setting the ScrollViewer to a pixel-based scrolling there is no more concept of logic units but only pixels!!!

查看更多
啃猪蹄的小仙女
3楼-- · 2019-01-05 05:01

UI Virtualization

I’m often asked if there is a way to work around this limitation. Well, anything is possible, but there is no easy workaround. You would have to re-implement significant portions of the current virtualization logic to combine pixel-based scrolling with UI virtualization. You would also have to solve some interesting problems that come with it. For example, how do you calculate the size of the thumb when the item containers have different heights? (Remember that you don’t know the height of the virtualized containers – you only know the height of the containers that are currently displayed.) You could assume an average based on the heights you do know, or you could keep a list with the item heights as items are brought into memory (which would increase accuracy of the thumb size as the user interacts with the control). You could also decide that pixel-based scrolling only works with items that are of the same height – this would simplify the solution. So, yes, you could come up with a solution to work around this limitation, but it’s not trivial.

查看更多
登录 后发表回答