WPFGrid布局

这篇博客介绍了WPF中的Grid布局,通过XML代码展示了如何创建一个包含两列四行的Grid,并详细解释了ColumnDefinitions和RowDefinitions的用法。内容包括设置单元格宽度、高度,以及使用Grid.Column和Grid.Row属性定位元素。示例中,Grid被用于创建登录窗口,包含用户名、密码和确认密码输入框以及一个确认按钮,展示了Grid.ColumnSpan属性用于合并单元格的功能。
摘要由CSDN通过智能技术生成

WPF中Grid布局XMAl<Grid Width="200" Height="100" >
<Window x:Class="wpfyonghukongjian.login"

        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"

        xmlns:local="clr-namespace:wpfyonghukongjian"

        mc:Ignorable="d"

        Title="login" Height="150" Width="300">

    <Grid>

        <!--定义了两列-->

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="Auto"/>

            <ColumnDefinition Width="100*"/>

        </Grid.ColumnDefinitions>

        <!--定义了四行-->

        <Grid.RowDefinitions>

            <RowDefinition Height="25"/>

            <RowDefinition Height="25"/>

            <RowDefinition Height="25"/>

            <RowDefinition Height="25"/>

        </Grid.RowDefinitions>

        <TextBlock Grid.Row="0" Grid.Column="0" TextAlignment="Right" Text="用户名:" Name="UserName" />

        <!--第一行第一列-->

        <TextBlock Grid.Row="1" Grid.Column="0" TextAlignment="Right" Text="密码:" Name="pass"/>

        <TextBlock Grid.Row="2" Grid.Column="0" TextAlignment="Right" Text="确认密码:" Name="repass"/>

        <Button Grid.Row="3" Grid.ColumnSpan="2" Height="23" Width="100" Content="确认" Click="Button_Click" Name="btn"/>

        <!--Grid.ColumnSpan="2":合并单元格-->

        <TextBox Name="TxtBoxName" Grid.Row="0" Grid.Column="1" Text=""  Width="200"/>

        <!--第一行第二列-->

        <PasswordBox Name="pass1" Grid.Row="1" Grid.Column="1" Width="200"/>

        <!--密码框-->

        <PasswordBox Name="pass2" Grid.Row="2" Grid.Column="1"  Width="200"/>

    </Grid>

</Window>

效果如图所示

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值