silverlight 5开发【vb版】(10)- 布局控件

1、布局控件主要有canvas,grid,stackpanel

2、canvas提供了一个空白空间,是简单的,可以操作canvas.left和canvas.top来进行控件在canvas的位置

grid可以提供随着浏览器窗口大小改变自动调整其内的控件的位置等,将空间划分为多行和多列

stackpanel提供一个纵向或横向排列控件的机制

3、下面是一个使用了3个布局控件的例子

Partial Public Class MainPage
    Inherits UserControl

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Button1.SetValue(Canvas.TopProperty, 20.0)
    End Sub
End Class

 

<UserControl x:Class="SilverlightApplication1.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:DesignHeight="300" d:DesignWidth="400" Margin="0">

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="126" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="29" />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Canvas Height="90" HorizontalAlignment="Left" Margin="12,0,0,0" Name="Canvas1" VerticalAlignment="Top" Width="237" Grid.Row="3">
            <Button Content="Button" Height="29" Name="Button1" Width="94" Canvas.Left="63" Canvas.Top="37" />
        </Canvas>
        <StackPanel Grid.Row="1" Height="90" HorizontalAlignment="Left" Margin="21,0,0,0" Name="StackPanel1" VerticalAlignment="Top" Width="253">
            <CheckBox Content="CheckBox" Height="16" Name="CheckBox1" />
            <CheckBox Content="CheckBox" Height="16" Name="CheckBox2" />
            <CheckBox Content="CheckBox" Height="16" Name="CheckBox3" />
            <StackPanel Height="33" Name="StackPanel2" Width="226" Orientation="Horizontal">
                <Button Content="Button" Height="18" Name="Button4" Width="50" />
                <Button Content="Button" Height="23" Name="Button2" Width="75" />
                <Button Content="Button" Height="23" Name="Button3" Width="75" />
            </StackPanel>
        </StackPanel>
    </Grid>
</UserControl>

 

 


silverlight 5开发【vb版】(10)- 布局控件
 

 

你可能感兴趣的:(silverlight)