Using a stackpanel control in Silverlight XAML

The StackPanel control is a container control that allows you to add child controls similar to the Canvas and Grid controls. The StackPanel automatically lays out controls evenly either horizontally or vertically. The orientation of the StackPanel is configured by setting the Orientation property to either Vertical or Horizontal.

The following example uses a StackPanel to line up a group of RadioButton controls in a Canvas.

<Canvas x:Name=”LayoutRoot” Background=”LightGray”>
<StackPanel Background=”White”
Orientation=”Vertical”
Canvas.Top=”50” Canvas.Left=”50”
Height=”100” Width=”100”>
<RadioButton Content=”Option A”
HorizontalAlignment=”Center”/>
<RadioButton Content=”Option B”
HorizontalAlignment=”Center”/>
<RadioButton Content=”Option C”
HorizontalAlignment=”Center”/>
<RadioButton Content=”Option D”
HorizontalAlignment=”Center”/>
</StackPanel>
</Canvas>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.