StackPanel
This arranges its sub-controls in horizontal lines. This WPF control stacks them, one upon another. It is easy to use and helps solve some user interface problems.
To begin, please drag a StackPanel
to your WPF window. The StackPanel
accepts sub-controls. In this example, I added 4 CheckBox
controls to it.
I added 4 CheckBox
controls and changed their Content attributes. They each indicate a breakfast food. In the screenshot we see the visual display of the WPF program.
StackPanel
contains all sorts of items you could eat for breakfast, such as eggs, pancakes, muffins and toast.<Window x:Class="WpfApplication22.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Breakfast" Height="350" Width="525"> <Grid> <StackPanel HorizontalAlignment="Left" Height="100" Margin="10,10,0,0" VerticalAlignment="Top" Width="100"> <CheckBox Content="Eggs"/> <CheckBox Content="Pancakes"/> <CheckBox Content="Muffins"/> <CheckBox Content="Toast"/> <CheckBox Content="Bacon"/> </StackPanel> </Grid> </Window>
A StackPanel
is similar to a WrapPanel
, except each element occupies an entire "line" in the StackPanel
. The WrapPanel
may be preferred in certain programs.
WrapPanel
will lead to a better use of space.With StackPanel
, we stack controls one after another. It is possible to arrange controls in this way without StackPanel
. But StackPanel
makes this arrangement less error-prone.