- Back to Home »
- WPF »
- XAML Stackpanel layout control example
Posted by :
Sudhir Chekuri
Thursday, 3 October 2013
StackPanel
Stackpanel is used to hold multiple child controls inside it which are arranged in horizontal or vertical direction.orientation is the property used to mention the direction of flow of elements inside stackpanel.
by default stackpanel will have vertical orientation.
xaml code of stackpanel with three shapes inside it as follows
<StackPanel>
<Rectangle Fill="Red" Width="100" Height="100"></Rectangle>
<Ellipse Fill="Blue" Width="100" Height="100"></Ellipse>
<Polygon Fill="Green" Width="100" Height="100" Points="0,0 275,0 275,200"></Polygon> </StackPanel>
windows store apps development c# stackpanel example output |
XAML Stackpanel Code with different orientations
<Window x:Class="WpfAppLayouts.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2" Height="300" Width="300">
<Grid>
<StackPanel Orientation="Vertical">
<!-- Vertical is the default -->
<Label Background="Red">Red</Label>
<Label Background="LightGreen">Green</Label>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Background="Red">Red</Label>
<Label Background="LightGreen">Green</Label>
<Label Background="LightBlue">Blue</Label>
<Label Background="Yellow">Yellow</Label>
<Label Background="Orange">Orange</Label>
</StackPanel>
</Grid>
</Window>