#389 – Wrap a Panel in A ScrollViewer to Provide Scrolling Support
September 19, 2011 5 Comments
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"/> </StackPanel> </ScrollViewer>
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.
Pingback: Dew Drop – September 19, 2011 | Alvin Ashcraft's Morning Dew
Pingback: #883 – ScrollViewer Is a ContentControl | 2,000 Things You Should Know About WPF
Pingback: #887 – The Difference between Disabled and Hidden Scrollbar Visibility | 2,000 Things You Should Know About WPF
Pingback: #888 – Different Ways to Scroll Content in a ScrollViewer | 2,000 Things You Should Know About WPF
Pingback: #1,006 – Scrollbars in a ListBox Appear as Needed | 2,000 Things You Should Know About WPF