Positioning UI Elements with a Grid
<UserControl x:Class='SilverlightApplication3.MainPage'
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
xmlns:d='http://schemas.microsoft.com/expression/blend/2008'
xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006'
mc:Ignorable='d'
d:DesignWidth='640'
d:DesignHeight='480'>
<UserControl.Resources>
<Style TargetType="TextBlock" x:Key="TextBlockStyle">
<Setter Property="Foreground" Value="#FFCBCBDF"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" MinHeight="400" MinWidth="600">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF26302B"/>
<GradientStop Color="#FF26302B" Offset="1"/>
<GradientStop Color="#FF26302B" Offset="0.5"/>
<GradientStop Color="#FF748A7F" Offset="0.25"/>
<GradientStop Color="#FF748A7F" Offset="0.7"/>
</LinearGradientBrush>
</Grid.Background>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBlock Margin="4,4,4,4" Style="{StaticResource TextBlockStyle}"
Text="Silverlight" />
<TextBlock Margin="4,4,4,4" Padding="8,8"
Style="{StaticResource TextBlockStyle}" Text="Silverlight" />
<TextBlock Margin="4,4,4,4" Style="{StaticResource TextBlockStyle}"
Text="Silverlight" />
<TextBlock Margin="4,4,4,4" Style="{StaticResource TextBlockStyle}"
Text="Silverlight" />
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" >
<Rectangle MinHeight="40" Fill="#FFBB8C27" Stroke="#FF000000" Margin="4"
MinWidth="50" RadiusX="10" RadiusY="10" />
<Rectangle MinHeight="40" Fill="#FF6E6EEA" Stroke="#FF000000"
Margin="0,0,4,0" MinWidth="50" RadiusX="10" RadiusY="10"/>
<Rectangle MinHeight="40" Fill="#FF008000" Stroke="#FF000000" Margin="4,4"
MinWidth="50" RadiusX="10" RadiusY="10"/>
<Rectangle MinHeight="40" Fill="#FF00FFFF" Stroke="#FF000000" Margin="4,0"
MinWidth="50" RadiusX="10" RadiusY="10"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal" >
<Rectangle MinHeight="40" Fill="#FFBB8C27" Stroke="#FF000000" Margin="4"
MinWidth="50" RadiusX="10" RadiusY="10"/>
<Rectangle MinHeight="40" Fill="#FF6E6EEA" Stroke="#FF000000"
Margin="0,0,4,0" MinWidth="50" RadiusX="10" RadiusY="10"/>
<Rectangle MinHeight="40" Fill="#FF008000" Stroke="#FF000000" Margin="4,4"
MinWidth="50" RadiusX="10" RadiusY="10"/>
<Rectangle MinHeight="40" Fill="#FF00FFFF" Stroke="#FF000000" Margin="4,0"
MinWidth="50" RadiusX="10" RadiusY="10"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBlock Margin="4,4,4,4" Style="{StaticResource TextBlockStyle}"
Text="Silverlight" />
<TextBlock Margin="4,4,4,4" Style="{StaticResource TextBlockStyle}"
Text="Silverlight" />
<TextBlock Margin="4,4,4,4" Padding="8,8"
Style="{StaticResource TextBlockStyle}" Text="Silverlight" />
<TextBlock Margin="4,4,4,4" Style="{StaticResource TextBlockStyle}"
Text="Silverlight" />
</StackPanel>
</Grid>
</UserControl>
Related examples in the same category