WPF 界面布局必知基础

WPF 界面布局必知基础

<Window x:Class="WpfApp1728.MainWindow"
        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:WpfApp1728"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">

    <!--<DockPanel>
        <Button Content="top Button" DockPanel.Dock="Top" Height="135" Width="370" ></Button>
    </DockPanel>-->
    <Grid ShowGridLines="True">
        <Grid.RowDefinitions>
            <!--行定义 3行4列的定义 -->
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
            
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <!--列定义-->
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Button Content="Left Top Button" />
       <!--1 指定行 Grid.Row="2" 2 指定列 Grid.Column="3" 控制按钮的位置。把附加属性用好,就基本够用了。-->
        <Button Content="Right Bottom Top Button" Grid.Row="2" Grid.Column="3" />
    </Grid>
</Window>

<Window x:Class="WpfApp1728.MainWindow"
        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:WpfApp1728"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">

    <!--<DockPanel>
        <Button Content="top Button" DockPanel.Dock="Top" Height="135" Width="370" ></Button>
    </DockPanel>-->
    <Grid ShowGridLines="True">
        <Grid.RowDefinitions>
            <!--行定义 3行4列的定义 -->
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
            
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <!--列定义-->
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Button Content="Left Top Button" />
       <!--1 指定行 Grid.Row="2" 2 指定列 Grid.Column="3" 控制按钮的位置。把附加属性用好,就基本够用了。-->
        <Button Content="Right Bottom Top Button" Grid.Row="2" Grid.Column="3" />
        <!--跨列设计属性 Grid.ColumnSpan--> 
        <Button Content="ColumnSpan Button" Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2" />
        <!--跨行属性 Grid.RowSpan-->
        <Button Content="RowSpan Button" Grid.Row="0" Grid.Column="1" Grid.RowSpan="3"/>
        
    </Grid>
</Window>

效果

  

 最小宽度设置,最小压缩设置也叫做。

  <Button Content="Left Top Button" MinWidth="80" />

最小宽度 

<!--列定义-->
            <ColumnDefinition MinWidth="100" Width="*"/>

效果

 自适应(到跟文字内容同样的高度) auto代码以及效果

   <!--行定义 3行4列的定义 -->
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>

   

 内外边距

 <Button Content="Right Bottom Top Button" Grid.Row="2" Margin="10,10,10,10" Grid.Column="3" />

外边距效果

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

济南医疗小程序状元

您的鼓励是我创作的最大动力!

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

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

打赏作者

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

抵扣说明:

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

余额充值