温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Silverlight学习笔记—3

发布时间:2020-06-18 13:59:17 来源:网络 阅读:232 作者:命苦 栏目:编程语言
在上一次学习了helloworld的项目结构,这次主要学习了silverlight的布局管理。
 
a.      Grid:网格布局。通过<Grid.RowDefinitions> 和 <Grid.ColumnDefinitions>来定义Grid的行和列,使用Grid.Row和Grid.Column两个附加属性指定子元素在Grid中显示的位置,这是一种非常灵活的布局方式。如下面的XAML声明:
<Gridx:Name="LayoutRoot"Background="#46461F" ShowGridLines="True">
    <Grid.RowDefinitions>
        <RowDefinition Height="120"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="100"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <TextBlock Grid.Row="0"Grid.Column="0" Text="UserName:" VerticalAlignment="Center" Foreground="White"></TextBlock>
    <TextBlock Grid.Row="1"Grid.Column="0" Text="Password:" VerticalAlignment="Center" Foreground="White"></TextBlock>
    <TextBox Grid.Row="0"Grid.Column="1" Width="200" Height="30"HorizontalAlignment="Left"></TextBox>
    <TextBox Grid.Row="1"Grid.Column="1" Width="200" Height="30"HorizontalAlignment="Left"></TextBox>
</Grid>

定义一个两行两列的Grid,做一个简单的用户登录的布局,为了明显起见,把ShowGridLines属性设为True,以便能够显示出边框线。同时,我们指定了第一行的高度为120,而第二行的则是剩余的高度,用*来指定。
 
b.       
StackPanel
StackPanel支持用行或列的方式来进行页面布局,默认情况下所有的子元素会垂直的排列显示,如下面的XAML声明三个矩形:
<StackPanelBackground="#46461F">
    <Rectangle Fill="#0099FF"Stroke="White"
               Width="100"Height="50" Margin="10"/>
    <Rectangle Fill="#0099FF"Stroke="White"
               Width="100"Height="50" Margin="10"/>
    <Rectangle Fill="#0099FF"Stroke="White"
               Width="100"Height="50" Margin="10"/>
</StackPanel>

当然我们也可以指定为水平排列,通过Orientation属性指定:
<StackPanel Background="#46461F" Orientation="Horizontal">
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI