Layout Panel in Windows Phone App Development

This article explains the layout panel in Windows Phone app development.

Introduction

The Windows Phone App User Interface is defined by the Extensible Application Markup Language (XAML). Using the XAML Language we use the UI element for the design interface. XAML follows the XML rules that are well-formed.

Currently Windows Phone App layout implements Canvas, Stack Panel and Grid.

  1. Canvas
  2. Stack Panel
  3. Grid

Canvas

A Canvas is used for defining an area in which any UI control works as a child object and the child object coordinates a match from the border of the Canvas. Every element has the Property “Canvas.Left” and “Canvas.Top” for declaring the element's position in the Canvas:

  1. <Canvas x:Name="canvaslayout" Width="300px" Height="600px" Background="Red"  >  
  2. <Button Canvas.Left="90px" Canvas.Top="250px" Background="Gray" Content="Button"   FontSize="30"></Button>  
  3. <TextBlock Canvas.Left="80px" Canvas.Top="200px" Text="TextBox" FontSize="40"></TextBlock>  
  4.  </Canvas>  

 

Figure 1: TextBox

StackPanel

A StackPanel is basically used for arranging a UI element horizontally and vertically using the orientation property of the StackPanel Tag. By default it arranges UI elements vertically. Stackpanel is mainly used for making a horizontal and vertical list and menu.

  1. <StackPanel Background="Bisque" Height="500px">  
  2.         <!-- Horizontal Menu-->  
  3.          <StackPanel Background="Bisque" Orientation="Horizontal" Height="199">  
  4.         <TextBlock Text="Menu1" FontSize="30" Margin="2 40" Foreground="Black"></TextBlock>  
  5.         <TextBlock Text="Menu2" FontSize="30" Margin="2 40" Foreground="Red"></TextBlock>  
  6.         <TextBlock Text="Menu3" FontSize="30" Margin="2 40" Foreground="Blue"></TextBlock>  
  7.         <TextBlock Text="Menu4" FontSize="30" Margin="2 40" Foreground="Green"></TextBlock>  
  8.           
  9.     </StackPanel>  
  10.         <!-- vertical Menu-->  
  11.         <TextBlock  Text="Menu1" FontSize="30"  Foreground="DarkBlue" SelectionHighlightColor="#FF531BD4"></TextBlock>  
  12.         <TextBlock Text="Menu2" FontSize="30"  Foreground="Brown"></TextBlock>  
  13.         <TextBlock Text="Menu3" FontSize="30"  Foreground="Orange"></TextBlock>  
  14.         <TextBlock Text="Menu4" FontSize="30"  Foreground="DarkMagenta"></TextBlock>  
  15.           
  16.    </StackPanel>  
Menu

 

Figure 2:Menu

Grid

A Grid is the most flexible layout in a Windows Phone App and arranges the content in rows and columns. We use many properties of a table in this layout, ike RowSpan and ColumnSpan. A child element of a grid layout is easily set in the layout. We can define a specific row and column for each element using a property.

  1. <Grid>  
  2.     <Grid.ColumnDefinitions>  
  3.         <ColumnDefinition Width="*"></ColumnDefinition>  
  4.         <ColumnDefinition Width="*"></ColumnDefinition>  
  5.         <ColumnDefinition Width="*"></ColumnDefinition>  
  6.     </Grid.ColumnDefinitions>  
  7.     <Grid.RowDefinitions>  
  8.         <RowDefinition Height="*"></RowDefinition>  
  9.         <RowDefinition Height="*"></RowDefinition>  
  10.         <RowDefinition Height="*"></RowDefinition>  
  11.     </Grid.RowDefinitions>  
  12.     <Button Grid.Row="0" Grid.Column="0" Content="0-0" HorizontalAlignment="Center" Background="Red"></Button>  
  13.     <Button Grid.Row="2" Grid.Column="2" Content="2-2" HorizontalAlignment="Center" Background="Red"></Button>  
  14.     <Button Grid.Row="1" Grid.Column="1" Content="1-1" HorizontalAlignment="Center" Background="Red"></Button>  
  15. </Grid>