Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why setting ScrollViewer.CanContentScroll to false disable virtualization

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.

like image 504
Park Wu Avatar asked Sep 16 '10 07:09

Park Wu


3 Answers

"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!!!

like image 124
rudigrobler Avatar answered Nov 16 '22 07:11

rudigrobler


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.

like image 30
egoroveo Avatar answered Nov 16 '22 06:11

egoroveo


You can restore the virtualization with VirtualizingPanel.ScrollUnit="Pixel" (in .NET >= 4.5).

like image 23
Hoddmimes Avatar answered Nov 16 '22 07:11

Hoddmimes