-
Book Overview & Buying
-
Table Of Contents
Windows Presentation Foundation 4.5 Cookbook
By :
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.
Make sure Visual Studio is up and running.
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 a ScrollViewer control inside the existing Grid.
Inside the ScrollViewer, add an Image element, and set its Source property to the image you added:
<ScrollViewer>
<Image Source="penguins.jpg" Stretch="None" />
</ScrollViewer> Set the Image Stretch property to None. This ensures the image is displayed in its original size.
Run the application. You should be able to scroll vertically as needed,...