#884 – Making a StackPanel Scroll More Intelligently

By default, when you place content in a ScrollViewer, the ScrollViewer itself decides how far to scroll the content each time that you click on the arrows included with the scrollbar (or use the arrow keys).

For example, we can place a vertical StackPanel within a ScrollViewer, where each element in the StackPanel is itself a panel containing an image and some text.  Each time we click on an arrow widget to scroll down by one increment, the content slides down a little bit.

884-001
884-002
However, we can tell the ScrollViewer that the StackPanel knows how to scroll itself by setting the ScrollViewer.CanContentScroll property to true.  The StackPanel now scrolls down one element a time when we click on the arrows.  That is, it scrolls down to the next child element, which in this case is the next image/text combination.

884-003

884-004

 

Advertisements