sliverlight3 学习 2, 布局
生活随笔
收集整理的這篇文章主要介紹了
sliverlight3 学习 2, 布局
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
silverlight三種布局方式
1,Canvas 定義一個區域,在此區域內,您可以使用相對于 Canvas 區域的坐標顯式定位子元素。也就是我們常說的絕對定位。在窗口大小發生變化時,位于Canvas內的子元素坐標不會發生變化。
在子元素中可以通過設置Canvas.Left 和 Canvas.Top 進行絕對定位。值得注意的是,在一個Canvas中可以嵌套一個新的Canvas。
示例:
<Canvas Width="640" Height="480" >
<input:AutoCompleteBox x:Name="MyACbox" Canvas.Left="100" Canvas.Top="100" IsTextCompletionEnabled="False" Width="200" Height="25" HorizontalAlignment="Left"></input:AutoCompleteBox>
</Canvas>
MainPage.xaml.cs
MyACbox.ItemsSource = new string[]
{
"中華人民共和國",
"香港特別行政區",
"中國北京"
};
?
2,Grid 定義由行和列組成的靈活網格區域。
可以通過使用 Grid.Column 和 Grid.Row 附加屬性,在 Grid 的特定單元格中定位子元素。
Grid在默認情況下包含一行和一列。可以使用 ColumnDefinitions 和 RowDefinitions 為Grid添加行或列。
示例:
?
<Grid x:Name="MyGrid" ShowGridLines="True" Background ="AliceBlue"><Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120" ></ColumnDefinition>
<ColumnDefinition Width="*" ></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="TestU" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<input:AutoCompleteBox x:Name="MyACbox" Margin="5" Grid.Row="0" Grid.Column="1" IsTextCompletionEnabled="False" Width="200" Height="25" HorizontalAlignment="Left"></input:AutoCompleteBox>
</Grid>
3,StackPanel 將子元素排列成一行或一列
?
?
<StackPanel x:Name="MyGrid" Background ="AliceBlue" Orientation="Horizontal"><Button Content="Button1" Width="150" Height="120" Margin="10" BorderBrush="Black"></Button>
<Button Content="Button2" Width="150" Height="120" Margin="10" BorderBrush="Black"></Button>
<Button Content="Button3" Width="150" Height="120" Margin="10" BorderBrush="Black"></Button>
</StackPanel>
?
?
<StackPanel x:Name="MyGrid" Background ="AliceBlue" ><Button Content="Button1" Width="150" Height="120" Margin="10" BorderBrush="Black"></Button>
<Button Content="Button2" Width="150" Height="120" Margin="10" BorderBrush="Black"></Button>
<Button Content="Button3" Width="150" Height="120" Margin="10" BorderBrush="Black"></Button>
</StackPanel>
下一章節,將從silverlight繪制功能開始學習。期間可能會簡單介紹silverlight控件。
轉載于:https://www.cnblogs.com/65876951/archive/2010/10/19/1855529.html
總結
以上是生活随笔為你收集整理的sliverlight3 学习 2, 布局的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用Flash模拟小车
- 下一篇: 为QT的Webkit 编写插件