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

本文介绍了Silverlight中三种常用的布局控件:Canvas、Grid 和 StackPanel 的使用方法,并通过实例展示了如何利用这些控件来实现不同需求的界面布局。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>

 

 



 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值