C# WPF开发基本控件

容器<Grid></Grid>介绍

window中的<Grid> 创建两行

  <RowDefinitions Height ="auto"/> //"auto"自适应按钮的最大尺寸 以最大尺寸定义的。 绝对尺寸"100"  "2*"上面一行的尺寸是下面一行的2倍
        <RowDefinitions/>
   <Grid.RowDefinitions>

创建两列

        <ColumnDefinitions/>
        <ColumnDefinitions/>
   <Grid.ColumnDefinitions>

添加按钮

 <Button width="100" Height="50"/>
        //<Button width="100" Height="100"/>

填充颜色

        <Bordor background="Red"/>
        <Bordor Grid.Row="1" background="Yellow"/>
        <Bordor Grid.Cloumn="1" background="Blue"/>
        <Bordor Grid.Row="1" Grid.Cloumn="1" background="Green"/>

RowDefinitions / ColumnDefinitions 用于给Grid分配行与列。

ColumnSpan / RowSpan 则用于设置空间元素的跨列与阔行。

        <Bordor background="Red" Grid.ColumnSpan ="2"/> //Grid.ColumnSpan ="2"占据两列空间  Grid. RowSpan ="2"占据两行空间

容器<StackPanel></StackPanel>介绍

StackPanel主要用于垂直或水平排列元素、在容器的可用尺寸内放置有限个元素,元素的尺寸总和(长/高)不允许超过StackPanel的尺寸, 否则超出的部分不可见

水平或垂直排列元素、Orientation属性分别: Horizontal / Vertical

<StackPanel Orientation="Horizontal"> // 按钮水平排列

<StackPanel>
    <Button width="100" Height="50"/> //默认从上往下排列
    <Button width="100" Height="50"/>
    <Button width="100" Height="50"/>
    <Button width="100" Height="50"/>
    <Button width="100" Height="50"/>
</StackPanel>

容器<WrapPanel></WrapPanel>介绍

WrapPanel默认排列方向与StackPanel相反、WrapPanel的Orientation默认为Horizontal。WrapPanel具备StackPanel的功能基础上具备在尺寸变更后自动适应容器的宽高进行换行换列处理。

水平或垂直排列元素、针对剩余空间不足会进行换行或换列进行排列 <WrapPanel Grid.row="1"Orientation=" Horizontal">

    <WrapPanel Grid.row="1" Orientation=" Horizontal">
        <Button width="100" Height="50"/> //默认水平排列
        <Button width="100" Height="50"/>
        <Button width="100" Height="50"/>
        <Button width="100" Height="50"/>
        <Button width="100" Height="50"/>
    </WrapPanel>

容器<DockPanel></DockPanel>介绍

根据容器的边界、元素进行Dock.Top、Left、Right、Bottom设置。

默认DockPanel中的元素具备DockPanel.Dock属性, 该属性为枚举具备: Top、Left、Right、Bottom。 默认情况下, DockPanel中的元素不添加DockPanel.Dock属性, 则系统则会默认添加 Left。

DockPanel有一个LastChildFill属性, 该属性默认为true, 该属性作

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

可喜~可乐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值