#389 – Wrap a Panel in A ScrollViewer to Provide Scrolling Support

The layout containers in WPF do not automatically provide scrolling support.  To scroll the content in a container, however, you can wrap it in a ScrollViewer control.

    <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
        <StackPanel Orientation="Vertical" >
            <Label Content="I am happy to join with you today in what will go down in history as the greatest demonstration for freedom in the history of our nation." />
            <Label Content="Some famous speeches:"/>
            <Label Content="I Have a Dream. --MLK" />
            <Label Content="Inaugural Address --JFK"/>
            <Label Content="First Inaugural --FDR"/>
            <Label Content="Pearl Harbor Address --FDR"/>
            <Label Content="1976 DNC Keynote --Barbara Jordan"/>

Notice that we’ve set the visibility of both scrollbars to Auto. By default, though, the horizontal scrollbar is disabled and the vertical scrollbar is visible.

You can set the HorizontalScrollbarVisibility and VerticalScrollbarVisibility properties to one of the following: Disabled, Visible, Auto or Hidden.