Sdílet prostřednictvím


ScrollBarVisibility Enumeration

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Specifies the visibility of a scrollbar within a ScrollViewer control.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Enumeration ScrollBarVisibility
public enum ScrollBarVisibility
<object property="enumMemberName"/>

Members

Member name Description
Supported by Silverlight for Windows Phone Disabled A ScrollBar does not appear even when the viewport cannot display all of the content. The dimension of the content is set to the corresponding dimension of the ScrollViewer parent. For a horizontal ScrollBar, the width of the content is set to the ViewportWidth of the ScrollViewer. For a vertical ScrollBar, the height of the content is set to the ViewportHeight of the ScrollViewer.
Supported by Silverlight for Windows Phone Auto A ScrollBar appears and the dimension of the ScrollViewer is applied to the content when the viewport cannot display all of the content. For a horizontal ScrollBar, the width of the content is set to the ViewportWidth of the ScrollViewer. For a vertical ScrollBar, the height of the content is set to the ViewportHeight of the ScrollViewer.
Supported by Silverlight for Windows Phone Hidden A ScrollBar does not appear even when the viewport cannot display all of the content. The dimension of the ScrollViewer is not applied to the content.
Supported by Silverlight for Windows Phone Visible A ScrollBar always appears. The dimension of the ScrollViewer is applied to the content. For a horizontal ScrollBar, the width of the content is set to the ViewportWidth of the ScrollViewer. For a vertical ScrollBar, the height of the content is set to the ViewportHeight of the ScrollViewer.

Remarks

Use this enumeration to set the HorizontalScrollBarVisibility and VerticalScrollBarVisibility property values of the ScrollViewer control.

The member values of this enumeration specify ScrollBar visibility in a given direction. These member values also specify whether the corresponding ScrollViewer dimension is applied to its enclosed content.

When you apply the ViewportWidth or ViewportHeight to ScrollViewer content, you set the viewport size for the content.

Examples

The following example shows how to use the ScrollBarVisibility enumeration members to set the HorizontalScrollBarVisibility property of a ScrollViewer control.

<StackPanel>
    <ScrollViewer HorizontalScrollBarVisibility="Auto">
        <Grid VerticalAlignment="Top" HorizontalAlignment="Left">
            <Rectangle Fill="LightGray" Width="450" Height="200"></Rectangle>
            <TextBlock TextWrapping="Wrap" Margin="10,10,10,10">
            Auto. Horizontal scroll bars is shown if the content 
            is wider than the viewport.</TextBlock>

        </Grid>
    </ScrollViewer>
    <ScrollViewer HorizontalScrollBarVisibility="Hidden">
        <Grid>
            <Rectangle Fill="LightBlue" Width="550" Height="210" />
            <TextBlock TextWrapping="Wrap" Margin="10,10,10,10">Hidden. 
           Horizontal scroll bar is hidden if the content is larger than 
           the viewport, it is not shown.</TextBlock>
        </Grid>
    </ScrollViewer>
</StackPanel>

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

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