#319 – The StackPanel Stacks Controls Vertically or Horizontally
June 13, 2011 Leave a comment
StackPanel is a container that allows arranging its child controls in a single column vertically or a single row horizontally.
Like other panels, StackPanel contains child elements that are instances of the UIElement class.
<StackPanel> <Label Content="Gene Autry"/> <Button Content="I Like Gene"/> <Label Content="Roy Rogers"/> <Button Content="I Like Roy"/> <Label Content="Tex Ritter"/> <Button Content="I Like Tex"/> <Label Content="Jorge Negrete"/> <Button Content="I Like Jorge"/> </StackPanel>
By default, StackPanel stacks its controls vertically. You can stack them horizontally using the Orientation property. You can specify the orientation in XAML as either Horizontal or Vertical.
<StackPanel Orientation="Horizontal"> <Label Content="Gene Autry"/> <Button Content="I Like Gene"/> <Label Content="Roy Rogers"/> <Button Content="I Like Roy"/> <Label Content="Tex Ritter"/> <Button Content="I Like Tex"/> <Label Content="Jorge Negrete"/> <Button Content="I Like Jorge"/> </StackPanel>