原創|使用教程|編輯:郝浩|2015-07-28 15:38:31.000|閱讀 306 次
概述:本文講解了關于StackPanel和Grid元素的基礎。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
這是本系列的第2部分。在這里我將講解StackPanel和Grid元素。很多時候開發人員對于在何處放置包含StackPane或Grid元素的控制元件感到困惑。那么我們就來了解一些關于StackPane和Grid元素的東西。
StackPanel元素主要用在網格的頂部或者底部。因此,當你打算設計一個簡單的web應用程序時,你可以使用Windows Phone的StackPanel把頁面名稱放置在標題標簽中。
在知曉頁面名稱和應用程序名稱的情況下你可以就使用StackPanel了,簡單地說就是使用StackPanel展示頁面名稱并對一個系列的子元素進行橫向的或者縱向的排列。
<!--LayoutRoot is the root grid where all page content is placed--> <Grid x:Name="LayoutRoot" Background="Transparent"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <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="StackPanel" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> </StackPanel> <!--ContentPanel - place additional content here--> <StackPanel Margin="150"> <Rectangle Fill="Red" Width="100" Height="100" Margin="5" /> <Rectangle Fill="Green" Width="100" Height="100" Margin="5" /> <Rectangle Fill="Violet" Width="100" Height="100" Margin="5" /> <Rectangle Fill="Firebrick" Width="100" Height="100" Margin="5" /> <Rectangle Fill="White" Width="100" Height="100" Margin="5" /> </StackPanel> </Grid>
Grid元素提供了對于多個行列的排布的更加靈活的控制。對于Grid元素,你可以使用RowDefinition和ColumnDefinition這兩個屬性來對行和列設置;也可以在一個單元格中使用行和列的定義來設置如Textblock、TextBox、Hyperlinkbutton和Image這樣的控制元件。
下面的XAML顯示了如何創建一個有4行和2列的網格:
<Grid x:Name="LayoutRoot" Background="Transparent"> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="100"/> <RowDefinition Height="*"/> <RowDefinition Height="*"></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"></ColumnDefinition> <ColumnDefinition Width="*"></ColumnDefinition> </Grid.ColumnDefinitions> <!--TitlePanel contains the name of the application and page title--> <StackPanel x:Name="TitlePanel" Grid.ColumnSpan="2" 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> <!--ContentPanel - place additional content here--> <Rectangle Fill="BLUE" Grid.Column="0" Grid.Row="1"></Rectangle> <Rectangle Fill="RED" Grid.Column="1" Grid.Row="1"></Rectangle> <Rectangle Fill="pink" Grid.Column="0" Grid.Row="2"></Rectangle> <Rectangle Fill="Aqua" Grid.Column="1" Grid.Row="2"></Rectangle> <Rectangle Fill="BlueViolet" Grid.Column="0" Grid.Row="3"></Rectangle> <Rectangle Fill="DarkMagenta" Grid.Column="1" Grid.Row="3"></Rectangle> </Grid>
本文翻譯自
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn