Example ตัวอย่างการใช้ StackPanel บน Windows Phone
XAML
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<StackPanel Margin="20,20,20,0" Grid.Row="1">
<Rectangle Fill="Red" Width="50" Height="50" Margin="5" />
<Rectangle Fill="Blue" Width="50" Height="50" Margin="5" />
<Rectangle Fill="Green" Width="50" Height="50" Margin="5" />
</StackPanel>
<StackPanel x:Name="MyStackPanel" Grid.Row="2">
<TextBlock x:Name="TB1" Text="First Name" Width="168" HorizontalAlignment="Left"/>
<TextBlock x:Name="TB2" Text="Last Name" Width="172" HorizontalAlignment="Left"/>
<TextBlock x:Name="TB3" Text="Address" Width="172" HorizontalAlignment="Left"/>
</StackPanel>
</Grid>
VB.NET
Partial Public Class MainPage
Inherits PhoneApplicationPage
' Constructor
Public Sub New()
InitializeComponent()
Dim TB4 As New TextBlock()
TB4.Text = "Age"
MyStackPanel.Children.Insert(2, TB4)
End Sub
End Class
C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
TextBlock TB4 = new TextBlock();
TB4.Text = "Age";
MyStackPanel.Children.Insert(2, TB4);
}
}
Screenshot
แสดง StackPanel และการเพิ่ม elements ลงใน StackPanel ของ Windows Phone