Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight 3
ScrollViewer Class

  Switch on low bandwidth view
This page is specific to
Microsoft Silverlight 3

Other versions are also available for the following:
.NET Framework Class Library for Silverlight
ScrollViewer Class

Represents a scrollable area that can contain other visible elements.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
<TemplatePartAttribute(Name := "ScrollContentPresenter", Type := GetType(ScrollContentPresenter))> _
<TemplatePartAttribute(Name := "HorizontalScrollBar", Type := GetType(ScrollBar))> _
<TemplatePartAttribute(Name := "VerticalScrollBar", Type := GetType(ScrollBar))> _
Public NotInheritable Class ScrollViewer _
    Inherits ContentControl
Visual Basic (Usage)
Dim instance As ScrollViewer
C#
[TemplatePartAttribute(Name = "ScrollContentPresenter", Type = typeof(ScrollContentPresenter))]
[TemplatePartAttribute(Name = "HorizontalScrollBar", Type = typeof(ScrollBar))]
[TemplatePartAttribute(Name = "VerticalScrollBar", Type = typeof(ScrollBar))]
public sealed class ScrollViewer : ContentControl
XAML Object Element Usage
<ScrollViewer .../>

The ScrollViewer element encapsulates a content element and up to two ScrollBar controls. The extent includes all the content of the ScrollViewer. The visible area of the content is the viewport.

The HorizontalScrollBarVisibility and VerticalScrollBarVisibility properties control the conditions under which the vertical and horizontal ScrollBar controls appear. If they are set to Hidden, you can use ComputedHorizontalScrollBarVisibilityProperty and ComputedVerticalScrollBarVisibilityProperty in code to discover what their actual state is at run time.

Customizing the ScrollViewer Control

To apply the same property settings to multiple ScrollViewer controls, use the Style property. To change the visual structure and visual behavior of a ScrollViewer, copy and modify its default style and template. For more information, see Control Customization.

If a dependency property for a ScrollViewer is set by its default style, the property might change from its default value when the ScrollViewer appears in the application. For more information, see Dependency Property Value Precedence. You can get the default style and template for ScrollViewer from ScrollViewer Styles and Templates.

NoteNote:

Setting a visual property will only have an effect if that property is both present in ScrollViewer control's default template and is set by using a TemplateBinding. You can find a list of visual properties in the "Changing the Visual Structure of a Control" section of Customizing the Appearance of an Existing Control by Using a ControlTemplate.

The following XAML creates a large TextBlock inside a ScrollViewer, along with another copy of the TextBlock for comparison.

Run this sample

<!-- A large TextBlock. -->
<TextBlock Canvas.Top="60" Canvas.Left="20" Width="300" TextWrapping="Wrap" Text="I am the very model of a modern Major-General, I've information vegetable, animal, and mineral, I know the kings of England, and I quote the fights historical, From Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical, I understand equations, both the simple and quadratical, About binomial theorem I'm teeming with a lot o' news, With many cheerful facts about the square of the hypotenuse." />


<!-- The same large TextBlock, wrapped in a ScrollViewer. -->
<!-- It can be scrolled in either direction, since VerticalScrollBarVisibility -->
<!-- has a default value of Visible. -->
<ScrollViewer Height="200" Width="200" HorizontalScrollBarVisibility="Auto" Canvas.Top="60" Canvas.Left="340">
    <TextBlock Width="300" TextWrapping="Wrap" Text="I am the very model of a modern Major-General, I've information vegetable, animal, and mineral, I know the kings of England, and I quote the fights historical, From Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical, I understand equations, both the simple and quadratical, About binomial theorem I'm teeming with a lot o' news, With many cheerful facts about the square of the hypotenuse." />
</ScrollViewer>

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker