当前位置:网站首页>WPF study notes "WPF Layout Basics"
WPF study notes "WPF Layout Basics"
2022-07-30 04:34:00 【A solar storm】
WPF布局基础
综述:WPFSaid technology is a kind of page,WPFReasonable layout is using some layout in the container to the layout of the need to display the contents of the,在布局时,Use the controls is one of the most <Grid><StackPanel> Secondly some of the controls like <DockPanel>, <WrapPanel> Less use of it,很多需求 <Grid><StackPanel> 就可以完成啦, <DockPanel> 其实用 <Grid><StackPanel> 来表示.
一、 Grid 控件
1. Grid介绍
Grid As the name suggests is the grid layout,Divide the grid into a a grid,Each grid is to populate the content we,当然啦,Who is going to divide the grid yet?That's right is you,That how to position to each grid yet?Can use the coordinates,Do you want to is a two-dimensional array of that kind of locating way is(如下图).没错,Is the layout position,You may be thinking again,The grid size is divide the large areas of?没错.The default is divide,Now that the default word can special specifies the,那没错了,到这里,We will to a problem,Now that can specify,It must also automatically.没错,Can set the automatic adaptive control size.
2. 代码实例
- 第一步,划分格子
//第一步,划分格子
<Window x:Class="xx_MSS.Pages.InstrumentPages.StatisticInfoWindow"
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:xx_MSS.Pages.InstrumentPages"
mc:Ignorable="d"
Title="Instrument statistics" Height="450" Width="800">
<Grid>
<!--列定义-->
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<!---行定义-->
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
</Grid>
</Window>
就是这种效果
- 第二步、放置元素
<Window x:Class="xx_MSS.Pages.InstrumentPages.StatisticInfoWindow"
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:xx_MSS.Pages.InstrumentPages"
mc:Ignorable="d"
Title="Instrument statistics" Height="450" Width="800">
<Grid>
<!--列定义-->
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<!---行定义-->
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Content="第一个按钮" Grid.Column="0" Grid.Row="0"/>
<Button Content="第二个按钮" Grid.Column="0" Grid.Row="1"/>
<Button Content="第三个按钮" Grid.Column="1" Grid.Row="0"/>
<Button Content="第四个按钮" Grid.Column="1" Grid.Row="1"/>
</Grid>
</Window>
就是这种效果,很好理解吧,This size is specified it,That we ourselves can also specify
- 第三步、Specified percentage width
<Window x:Class="xx_MSS.Pages.InstrumentPages.StatisticInfoWindow"
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:xx_MSS.Pages.InstrumentPages"
mc:Ignorable="d"
Title="Instrument statistics" Height="450" Width="800">
<Grid>
<!--列定义-->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<!---行定义-->
<Grid.RowDefinitions>
<RowDefinition Height="45*" />
<RowDefinition Height="374*"/>
</Grid.RowDefinitions>
<Button Content="第一个按钮" Grid.Column="0" Grid.Row="0"/>
<Button Content="第二个按钮" Grid.Column="0" Grid.Row="1"/>
<Button Content="第三个按钮" Grid.Column="1" Grid.Row="0"/>
<Button Content="第四个按钮" Grid.Column="1" Grid.Row="1"/>
</Grid>
</Window>
就是这种效果,You can specify a specific value,可以用 1* 2* Said value ratio is 1 :2 之类的
- 第四步,Layout from adapted to control the width
<Window x:Class="xx_MSS.Pages.InstrumentPages.StatisticInfoWindow"
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:xx_MSS.Pages.InstrumentPages"
mc:Ignorable="d"
Title="Instrument statistics" Height="450" Width="800">
<Grid>
<!--列定义-->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<!---行定义-->
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Height="150" Width="120" Content="第一个按钮" Grid.Column="0" Grid.Row="0"/>
<Button Content="第二个按钮" Grid.Column="0" Grid.Row="1"/>
<Button Content="第三个按钮" Grid.Column="1" Grid.Row="0"/>
<Button Content="第四个按钮" Grid.Column="1" Grid.Row="1"/>
</Grid>
</Window>

二、StackPanel 控件
1、StackPanel 介绍
StackPanel Layout is actually is the stack layout,He tends to part,The direction of the horizontal or vertical arrangement,Where the content order is through we specified order,当然,Is the layout of the elements inside actually filled with the layout in the form of filling control,That said we specify each layout element alignment,

2、代码实例
- 第一种:默认垂直布局,
<Window x:Class="xx_MSS.Pages.InstrumentPages.StatisticInfoWindow"
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:xx_MSS.Pages.InstrumentPages"
mc:Ignorable="d"
Title="Instrument statistics" Height="450" Width="800">
<StackPanel>
<Button Content="第一个按钮"/>
<Button Content="第二个按钮" />
<Button Content="第三个按钮" />
<Button Content="第四个按钮" />
</StackPanel>
</Window>

- 第二种 水平布局
<Window x:Class="xx_MSS.Pages.InstrumentPages.StatisticInfoWindow"
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:xx_MSS.Pages.InstrumentPages"
mc:Ignorable="d"
Title="Instrument statistics" Height="450" Width="800">
<StackPanel Orientation="Horizontal">
<Button Content="第一个按钮"/>
<Button Content="第二个按钮" />
<Button Content="第三个按钮" />
<Button Content="第四个按钮" />
</StackPanel>
</Window>

- 第三种:填充内容
<Window x:Class="xx_MSS.Pages.InstrumentPages.StatisticInfoWindow"
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:xx_MSS.Pages.InstrumentPages"
mc:Ignorable="d"
Title="Instrument statistics" Height="450" Width="800">
<StackPanel Orientation="Horizontal">
<Button VerticalAlignment="Top" Content="第一个按钮"/>
<Button VerticalAlignment="Center" Content="第二个按钮" />
<Button VerticalAlignment="Bottom" Content="第三个按钮" />
<Button VerticalAlignment="Stretch" Content="第四个按钮" />
<Button Content="第五个按钮" />
</StackPanel>
</Window>

- 第四种,StackPanelWon't go to the content is more than the window
<Window x:Class="xx_MSS.Pages.InstrumentPages.StatisticInfoWindow"
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:xx_MSS.Pages.InstrumentPages"
mc:Ignorable="d"
Title="Instrument statistics" Height="450" Width="100">
<StackPanel Orientation="Horizontal">
<Button Content="第一个按钮" DockPanel.Dock="Top"/>
<Button Content="第二个按钮" DockPanel.Dock="Left"/>
<Button Content="第三个按钮" DockPanel.Dock="Bottom"/>
<Button Content="第四个按钮" DockPanel.Dock="Right"/>
<Button Content="第五个按钮" />
</StackPanel>
</Window>

三、 DockPanel 控件
1、DockPanel 介绍
Dock is similar to the window that style、Anyway, keep in mind is to write the finish all the corresponding position of,Parked position is all around,There is no central dock that saying
2、代码实例
- 第一种
<Window x:Class="xx_MSS.Pages.InstrumentPages.StatisticInfoWindow"
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:xx_MSS.Pages.InstrumentPages"
mc:Ignorable="d"
Title="Instrument statistics" Height="450" Width="800">
<DockPanel>
<Button Content="第一个按钮" DockPanel.Dock="Top"/>
<Button Content="第二个按钮" DockPanel.Dock="Left"/>
<Button Content="第三个按钮" DockPanel.Dock="Right"/>
<Button Content="第四个按钮" DockPanel.Dock="Bottom"/>
<Button Content="第五个按钮" />
</DockPanel>
</Window>

Inside place in,May effect is not the same
<Window x:Class="xx_MSS.Pages.InstrumentPages.StatisticInfoWindow"
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:xx_MSS.Pages.InstrumentPages"
mc:Ignorable="d"
Title="Instrument statistics" Height="450" Width="800">
<DockPanel>
<Button Content="第一个按钮" DockPanel.Dock="Top"/>
<Button Content="第二个按钮" DockPanel.Dock="Left"/>
<Button Content="第三个按钮" DockPanel.Dock="Bottom"/>
<Button Content="第四个按钮" DockPanel.Dock="Right"/>
<Button Content="第五个按钮" />
</DockPanel>
</Window>

四、 WrapPanel 控件
1、WrapPanel 介绍
WrapPanel其实和StackPanel很类似,Also there are horizontal and vertical layout,默认是水平,只是说,StackPanelDon't automatically change the layout,WrapPanelIn window internal elements too much,Automatic transfer element to the next line,
2、代码实例
- 第一种
<Window x:Class="xx_MSS.Pages.InstrumentPages.StatisticInfoWindow"
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:xx_MSS.Pages.InstrumentPages"
mc:Ignorable="d"
Title="Instrument statistics" Height="450" Width="700">
<WrapPanel>
<Button Content="第一个按钮" DockPanel.Dock="Top"/>
<Button Content="第二个按钮" DockPanel.Dock="Left"/>
<Button Content="第三个按钮" DockPanel.Dock="Bottom"/>
<Button Content="第四个按钮" DockPanel.Dock="Right"/>
<Button Content="第五个按钮" />
</WrapPanel>
</Window>

Content excess window size
<Window x:Class="xx_MSS.Pages.InstrumentPages.StatisticInfoWindow"
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:xx_MSS.Pages.InstrumentPages"
mc:Ignorable="d"
Title="Instrument statistics" Height="450" Width="300">
<WrapPanel>
<Button Content="第一个按钮" DockPanel.Dock="Top"/>
<Button Content="第二个按钮" DockPanel.Dock="Left"/>
<Button Content="第三个按钮" DockPanel.Dock="Bottom"/>
<Button Content="第四个按钮" DockPanel.Dock="Right"/>
<Button Content="第五个按钮" />
</WrapPanel>
</Window>

边栏推荐
- MySQL 字符串拼接 - 多种字符串拼接实战案例
- Chapter8 Support Vector Machines
- protobuf 中复合数据类型的读写
- 2.6 Radix sort (bucket sort)
- 05全局配置文件application.properties详解
- [Awards every week] The "Edge Containers" track of the Cloud Native Programming Challenge invites you to fight!
- BGP的简单实验
- Taobao H5 interface to obtain app data 6.0 format
- 复现XXL-JOB 任务调度中心后台任意命令执行漏洞
- MySQL 操作语句大全(详细)
猜你喜欢

Thinkphp 5.0.24变量覆盖漏洞导致RCE分析

2.4 hill sorting

Thymeleaf简介

1. Get data - requests.get()

DAY17:弱口令的探测与测试

Excellent MySQL interview questions, 99% must ask in preparation for August!I can't pass the interview

MYSQL 唯一约束

六、读取应用配置+日志配置

Introduction to database - MySQL simple introduction
![[SQL] at a certain correlation with a table of data update another table](/img/66/4dff4383509e5d25890d8a24720de6.png)
[SQL] at a certain correlation with a table of data update another table
随机推荐
2.4 hill sorting
四、Web开发
【周周有奖】云原生编程挑战赛“边缘容器”赛道邀你来战!
(Problem practice) Conditional probability + weight line segment tree + FWT + suffix array
2.5 Quick Sort
复现XXL-JOB 任务调度中心后台任意命令执行漏洞
需求设计文档和产品经理的角色改变
Weight line segment tree + line segment tree split/merge + CF1659D
swagger使用教程——快速使用swagger
unity初学5 摄像机跟随,边界控制以及简单的粒子控制(2d)
小程序 wx.miniProgram.navigateTo 跳转地址不能是tabbar地址
A brief introduction to the SSM framework
JQ源码分析(环境处理)
C. Travelling Salesman and Special Numbers (二进制 + 组合数)
Mini Program wx.miniProgram.navigateTo jump address cannot be tabbar address
labelme的使用技巧
Many overseas authoritative media hotly discuss TRON: laying the foundation for the decentralization of the Internet
代码开源设计实现思路
商品管理系统数据库设计--SQL Server
数据目录是什么?为何需要它?