首页 > 其他分享 >WPF学习-布局

WPF学习-布局

时间:2023-03-21 23:11:38浏览次数:32  
标签:布局 默认 学习 效果图 Table WPF Border

1.  Grid布局 ,(Table 布局)

两行两列布局, 

Border  0 行 0 列默认开始

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

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

        <Border Background="Red"></Border>
        <Border Grid.Row="1" Background="Yellow"></Border>
        <Border Grid.Column="1"  Background="Blue"></Border>
        <Border Grid.Row="1" Grid.Column="1" Background="Green"></Border>
    </Grid>
</Window>

效果图:

 

2. StackPanel 布局

默认垂直布局 ,一旦超出区域限制后不限制

   <StackPanel Orientation="Horizontal">  改成水平排列

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <StackPanel>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
        </StackPanel>
    </Grid>

效果图:

3.  WrapPanel 布局, ( float布局)

默认水平排序

 

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <StackPanel Orientation="Horizontal">
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
        </StackPanel>

        <WrapPanel Grid.Row="1">
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
        </WrapPanel>
    </Grid>

效果:

 

4. DockPanel  停靠 (flex 布局)

默认横向填充,

    <Grid>

        <DockPanel>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
            <Button Width="100" Height="40"/>
        </DockPanel>
    </Grid>

效果图:

默认横向填充,  最后一个元素占据整个布局, 居中显示.

 

停靠布局

注意设置: LastChildFill="False"

    <Grid>

        <DockPanel LastChildFill="False">
            <Button Width="100" Height="40" DockPanel.Dock="Left"/>
            <Button Width="100" Height="40" DockPanel.Dock="Top"/>
            <Button Width="100" Height="40" DockPanel.Dock="Right"/>
            <Button Width="100" Height="40" DockPanel.Dock="Bottom"/>
        </DockPanel>
    </Grid>

效果图:

 

5. Uniform 布局 (Table)

均分所有区域

设置三行三列布局

        <UniformGrid Columns="3" Rows="3">
            <Button></Button>
            <Button></Button>
            <Button></Button>
            <Button></Button>
            <Button></Button>
            <Button></Button>
            <Button></Button>
            <Button></Button>
        </UniformGrid>

效果图:

 

6.  布局Demo 案例

Border : 类似background 属性 

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="40"></RowDefinition>
            <RowDefinition ></RowDefinition>
        </Grid.RowDefinitions>

        <!--装饰器元素-->
        <Border Background="#7671d8"></Border>

        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="200"></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Border Background="Blue"></Border>

            <Grid Grid.Column="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="0.5*"></RowDefinition>
                    <RowDefinition></RowDefinition>
                    <RowDefinition></RowDefinition>
                </Grid.RowDefinitions>
                <Border Margin="5" Background="#7671d8"></Border>
                <Border Margin="5" Background="#429ecd" Grid.Column="1"></Border>
                <Border Margin="5" Background="#7671d8" Grid.Column="2"></Border>
                <Border Margin="5" Background="#5ac4b6" Grid.Column="3"></Border>
                <Border Margin="5" Background="#d9707f" Grid.Column="4"></Border>

                <Border Background="Red" Grid.Row="1" Grid.ColumnSpan="3" Margin="5">
                </Border>

                <Border Background="Yellow" Grid.Row="1" Grid.Column="3" Grid.ColumnSpan="2" Margin="5">
                </Border>

                <Border Grid.Row="2" Background="Blue" Margin="5" Grid.ColumnSpan="3"></Border>
                <Border Grid.Row="2" Grid.ColumnSpan="2" Grid.Column="3" Background="Green" Margin="5"></Border>
                
            </Grid>
        </Grid>

    </Grid>

标签:布局,默认,学习,效果图,Table,WPF,Border
From: https://www.cnblogs.com/voidobject/p/17241758.html

相关文章

  • 数据结构算法学习前言
    数据结构算法学习写在前面:今天是2023-03-21,上一次接触算法是在公司导师的带领下,学习了数据结构算法,他一题一题讲给我的,但是当时却不太争气,并没有掌握太多,由于这段时间......
  • 李沐动手学深度学习环境配置(Win)
    环境配置(Win)一、安装Minicondahttps://docs.conda.io/en/latest/miniconda.html更改镜像源condanotepad.condarcpypipipconfigsetgloba......
  • 学习Linux只要学会这个命令就够了!
    大家好,我是良许。这段时间又是搬家,又是找新办公室,现在终于安顿下来了,有时间给大家分享干货了。今天给大家介绍一个Linux超级实用命令,有了这个命令,你就可以愉快使用Linu......
  • jenkins学习笔记之十五:SonarSQube API使用
    本章主要通过SonarSQubeAPI在pipeline第一次执行时就指定自定义的质量配置和质量阈API 文档:http://192.168.1.134:9000/web_api一、编写sonarAPI(sonarapi.groovy)注......
  • 3.21学习总结
    2.4.3日期和时间组件(下)分类 Android基础入门教程本节引言:本节我们来继续学习Android系统给我们提供的几个原生的Date&Time组件,他们分别是:DatePicker(日期选择器),Ti......
  • node学习四之npm知识点
    1.版本号知识点使用NPM下载和发布代码时都会接触到版本号。NPM使用语义版本号来管理代码,这里简单介绍一下。语义版本号分为X.Y.Z三位,分别代表主版本号、次版本号和补丁版本......
  • 初来乍到,开始学习的输出
     一、自我介绍JAVA程序员,入行3年了,一直在默默的学习,对于知识,输入方式复杂多样,而输出的方式也仅有通过日常工作的代码输出。这种输出,针对性不强,不能很好的锻炼。所谓,温故......
  • 大恒相机-Winform\WPF 视频流显示
    usingSystem;usingSystem.Collections.Generic;usingSystem.Drawing;usingSystem.Drawing.Imaging;usingSystem.IO;usingSystem.Runtime.InteropServices;usin......
  • 1. 继承的学习和使用
    继承的学习和使用继承概述继承是面向对象三大特性之一(封装,继承,多态)继承使子类拥有父类的属性和方法,并且可以定义自己独有的属性和方法继承的格式关键字:exte......
  • 算法学习
    算法    排序        选择            找到最小的index,然后再交换        冒泡            一直在换位置      ......