Skip to Main Content
Programming WPF, 2nd Edition
book

Programming WPF, 2nd Edition

by Chris Sells, Ian Griffiths
August 2007
Intermediate to advanced content levelIntermediate to advanced
864 pages
25h 52m
English
O'Reilly Media, Inc.
Content preview from Programming WPF, 2nd Edition

ScrollViewer

The ScrollViewer control allows oversized content to be displayed by putting it into a scrollable area. A ScrollViewer element has a single child. Example 3-35 uses an Ellipse element, but it could be anything. If you want to put multiple elements into a scrollable view, you would nest them inside a panel.

Example 3-35. ScrollViewer

<ScrollViewer HorizontalScrollBarVisibility="Auto">
  <Ellipse Fill="Green" Height="1000" Width="2000" />
</ScrollViewer>

If the content of a ScrollViewer is larger than the space available, the ScrollViewer can provide scroll bars to allow the user to scroll around the content, as ScrollViewer shows. By default, a ScrollViewer provides a vertical scroll bar, but not a horizontal one. In Figure 3-39, the HorizontalScrollBarVisibility property has been set to Auto, indicating that a horizontal scroll bar should be added if required.

ScrollViewer

Figure 3-39. ScrollViewer

This Auto visibility we've chosen for the horizontal scroll bar is different from the default vertical behavior. The VerticalScrollBarVisibility defaults to Visible, meaning that the scroll bar is present whether it is required or not.

There are two ways to make sure a scroll bar does not appear. You can set its visibility either to Disabled (the default for horizontal scroll bars) or to Hidden. The distinction is that Disabled constrains the logical size of the ScrollViewer's contents to be the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming C#, 4th Edition

Programming C#, 4th Edition

Jesse Liberty
Programming C# 10

Programming C# 10

Ian Griffiths

Publisher Resources

ISBN: 9780596510374Supplemental ContentErrata Page