--- title: "ScrollViewer Overview" description: Learn about the ScrollViewer control, which enables scrolling of content in Windows Presentation Foundation applications. See usage examples. ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" - "cpp" helpviewer_keywords: - "controls [WPF], ScrollViewer" - "ScrollViewer control [WPF], about ScrollViewer control" ms.assetid: 94a13b94-cfdf-4b12-a1aa-90cb50c6e9b9 --- # ScrollViewer Overview Content within a user interface is often larger than a computer screen's display area. The control provides a convenient way to enable scrolling of content in Windows Presentation Foundation (WPF) applications. This topic introduces the element and provides several usage examples. ## The ScrollViewer Control There are two predefined elements that enable scrolling in WPF applications: and . The control encapsulates horizontal and vertical elements and a content container (such as a element) in order to display other visible elements in a scrollable area. You must build a custom object in order to use the element for content scrolling. However, you can use the element by itself because it is a composite control that encapsulates functionality. The control responds to both mouse and keyboard commands, and defines numerous methods with which to scroll content by predetermined increments. You can use the event to detect a change in a state. A can only have one child, typically a element that can host a collection of elements. The property defines the sole child of the . ## Physical vs. Logical Scrolling Physical scrolling is used to scroll content by a predetermined physical increment, typically by a value that is declared in pixels. Logical scrolling is used to scroll to the next item in the logical tree. Physical scrolling is the default scroll behavior for most elements. WPF supports both types of scrolling. #### The IScrollInfo Interface The interface represents the main scrolling region within a or derived control. The interface defines scrolling properties and methods that can be implemented by elements that require scrolling by logical unit, rather than by a physical increment. Casting an instance of to a derived and then using its scrolling methods provides a useful way to scroll to the next logical unit in a child collection, rather than by pixel increment. By default, the control supports scrolling by physical units. and both implement and natively support logical scrolling. For layout controls that natively support logical scrolling, you can still achieve physical scrolling by wrapping the host element in a and setting the property to `false`. The following code example demonstrates how to cast an instance of to a and use content scrolling methods ( and ) defined by the interface. [!code-csharp[IScrollInfoMethods#3](~/samples/snippets/csharp/VS_Snippets_Wpf/IScrollInfoMethods/CSharp/Window1.xaml.cs#3)] [!code-vb[IScrollInfoMethods#3](~/samples/snippets/visualbasic/VS_Snippets_Wpf/IScrollInfoMethods/VisualBasic/Window1.xaml.vb#3)] ## Defining and Using a ScrollViewer Element The following example creates a in a window that contains some text and a rectangle. elements appear only when they are necessary. When you resize the window, the elements appear and disappear, due to updated values of the and properties. [!code-cpp[ScrollViewer#1](~/samples/snippets/cpp/VS_Snippets_Wpf/ScrollViewer/CPP/ScrollViewer_wcp.cpp#1)] [!code-csharp[ScrollViewer#1](~/samples/snippets/csharp/VS_Snippets_Wpf/ScrollViewer/CSharp/ScrollViewer_wcp.cs#1)] [!code-vb[ScrollViewer#1](~/samples/snippets/visualbasic/VS_Snippets_Wpf/ScrollViewer/VisualBasic/ScrollViewer.vb#1)] [!code-xaml[ScrollViewer#1](~/samples/snippets/xaml/VS_Snippets_Wpf/ScrollViewer/XAML/Pane1.xaml#1)] ## Styling a ScrollViewer Like all controls in Windows Presentation Foundation, the can be styled in order to change the default rendering behavior of the control. For additional information on control styling, see [Styling and Templating](styles-templates-overview.md). ## Paginating Documents For document content, an alternative to scrolling is to choose a document container that supports pagination. is for documents that are designed to be hosted within a viewing control, such as , that supports paginating content across multiple pages, preventing the need for scrolling. provides a solution for viewing content, which uses traditional scrolling to display content outside the realm of the display area. For additional information about document formats and presentation options, see [Documents in WPF](../advanced/documents-in-wpf.md). ## See also - - - - [How to: Create a Scroll Viewer](/previous-versions/dotnet/netframework-3.5/ms752352(v=vs.90)) - [Documents in WPF](../advanced/documents-in-wpf.md) - [ScrollBar Styles and Templates](scrollbar-styles-and-templates.md) - [Controls](../advanced/optimizing-performance-controls.md)