Xaml技术:浅谈Grid.ColumnDefinitions和Grid.RowDefinitions属性

Grid.RowDefinitions属性将Grid控件分行,属性值为RowDefinition标签,每一个RowDefinition标签将该Grid对象分为一行;

Grid.ColumnDefinitions属性将Grid控件分列,属性值为ColumnDefinition标签,每一个ColumnDefinition标签将该Grid对象分为一列;

在给每个方块添加空间时只需指定该控件的Grid.Column和Grid.Row附加属性值,前提是该控件要定义在Grid空间中,否则将找不到这两个属性,也就无法将该控件添加到指定方格中。

当指定的行或列的值大于Grid的单元格数量时,系统默认为最后一个,比如:

    <Grid x:Name="LayoutRoot" Background="Blue">
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>

        <Button Grid.Column="0" Grid.Row="0" Content=" 0  , 0"></Button>
        <Button Grid.Column="1" Grid.Row="1" Content=" 1  , 1"></Button>
        <Button Grid.Column="2" Grid.Row="2" Content=" 2  , 2"></Button>
    </Grid>

在该示例中,我们将Grid控件分为3行2列,而添加Button时我们却设定其位置分别为(0,0),(1,1),(2,2)。很明显,该Grid并不包含(2,2)--因为它只有2列,但是调试运行时系统并不会报错,而是出现下面的结果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值