ScrollViewer Class
This page is specific to:Microsoft Version:3.03.5Silverlight 34.0
.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)
Syntax

'Usage

Dim instance As ScrollViewer

'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
<ScrollViewer .../>
Remarks

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.

Examples

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>
Inheritance Hierarchy

System..::.Object
  System.Windows..::.DependencyObject
    System.Windows..::.UIElement
      System.Windows..::.FrameworkElement
        System.Windows.Controls..::.Control
          System.Windows.Controls..::.ContentControl
            System.Windows.Controls..::.ScrollViewer
Thread Safety

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

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

See Also

Reference

Other Resources

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View