#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.

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.





About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: