Creating a scrollable user interface
There are occasions when some data to display is larger than the display area; this requires scrolling capabilities. WPF provides that using a simple control, the ScrollViewer
.
Getting ready
Make sure Visual Studio is up and running.
How to do it...
We'll create a simple image viewer that provides scrollbars if necessary when viewing a large image:
- Create a new WPF application named
CH03.ScrollDemo
. - Add an image to the project. For example, you could select the
Penguins.jpg
file from the Pictures | Sample Pictures folder. - Open
MainWindow.xaml
. Add aScrollViewer
control inside the existingGrid
. - Inside the
ScrollViewer
, add anImage
element, and set itsSource
property to the image you added:<ScrollViewer> <Image Source="penguins.jpg" ...
Get Windows Presentation Foundation 4.5 Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.