#409 – 加入Grid中的子元素默认占满所在单元格(Child Elements in a Grid Size to Fit the Containing Cell)

默认情况下,Grid的子元素会自动调整大小占满其所在单元格。你通常不需要为其设置大小,它的大小会根据所在单元格变化而与单元格保持一致。

你也可以通过设置子元素的Margin 属性来设定其与单元格边距距离。

<Grid ShowGridLines="True">
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
 
    <Label Grid.Row="0" Grid.Column="0" Content="Larry" Margin="5" Background="Lavender"/>
    <Label Grid.Row="0" Grid.Column="1" Content="Moe" Margin="5" Background="Magenta"/>
    <Label Grid.Row="0" Grid.Column="2" Content="Curly" Margin="5" Background="Cornsilk"/>
 
    <CheckBox Grid.Row="1" Grid.Column="0" Margin="5" Content="Nose Tweak"/>
    <Button Grid.Row="1" Grid.Column="1" Margin="5" Content="Do Eye Poke" />
    <TextBox Grid.Row="1" Grid.Column="2" Margin="5" Text="Double slap"/>
</Grid>


原文地址:https://wpf.2000things.com/2011/10/17/409-child-elements-in-a-grid-size-to-fit-the-containing-cell/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值