ScrollViewer
A ScrollViewer
scrolls other controls. It is used as a container. We drag (or otherwise add) controls, nesting them inside the ScrollViewer
.
To use a ScrollViewer
please open the Toolbox and drag the control to your Window. So try dragging some Button
controls to its interior area.
In this example, I added a StackPanel
to the interior of the ScrollViewer
. In a StackPanel
, controls are "stacked" in one direction.
StackPanel
work just as well within a ScrollViewer
.Button
controls to the ScrollViewer
. I then added margin to the Buttons to make them larger in area.<Window x:Class="WpfApplication6.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <ScrollViewer HorizontalAlignment="Left" Height="299" Margin="10,10,0,0" VerticalAlignment="Top" Width="497"> <StackPanel> <Button Content="Button 1" HorizontalAlignment="Left" Margin="50" VerticalAlignment="Top" Width="75"/> <Button Content="Button 2" HorizontalAlignment="Left" Margin="50" VerticalAlignment="Top" Width="75"/> <Button Content="Button 3" HorizontalAlignment="Left" Margin="50" VerticalAlignment="Top" Width="75"/> </StackPanel> </ScrollViewer> </Grid> </Window>
ScrollViewer
is a layout control—it requires you to add controls to it before it is useful. Once you do this, though, you get a region that expands as much as needed.
TextBlock
description.Sometimes when designing programs, a "Preferences" dialog (Options) is a burden. At first, these windows have few controls—so you can just add Buttons to a Grid
.
ScrollViewer
might be helpful.ScrollViewer
, are easiest to work with.WPF is full of useful controls. A ScrollViewer
is not needed in many programs. But in "Options" windows, or other complex dialogs, it has its place.