~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
开发工具与关键技术:Visual Studio 2015 WPF XAML
作者:梅花开的冬天
撰写时间:2019 年 4 月 18 日
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WPF 使用响应式布局有一个简单快捷的方式,那就是使用 Grid 网格布局,并且是按份数布局,而且 Grid 里面的标签也不能设置长宽高,只能不设置(也就是让它值为 AUTO 默认为跟随父元素大小),这样的话,当页面大小发生改变时,Grid 网格式布局也会随之发生改变,缺点就不能使用网格式布局使用太过精细(复杂)的页面,只能布置一些简单点的页面这里拿我做的一个登入窗口作为例子,布局很丑,望勿介意
![001a8b2a1436b5318e814d9ed7089e9b.png](https://img-blog.csdnimg.cn/img_convert/001a8b2a1436b5318e814d9ed7089e9b.png)
我这里是直接定义的 10 个 然后将我想要显示的控件放进相对应的格子里,并且在那个格子里在细分出我想要将控件放置的地方
当然,也可以使用一点外边距来调整你控件的相对于父元素的位置,但是,,,Mgrin 这东西可不能设置份数大小的,只能设置绝对的大小,,所以当你窗口页面放大缩小比例不大的时候还好说,一旦当你放大缩小的比例很大的化,,,,,那页面可就乱套了,所以能不使用 Mgrin 就不要使用这东西,如果向要控件放的位置更理想一点,可以划分 Grid 时,划分更细一些就比如说下面的这个!
![f5377ba509681c0643b06017b686108e.png](https://img-blog.csdnimg.cn/img_convert/f5377ba509681c0643b06017b686108e.png)
这里给出登入页面的源代码
Tag="Text_Dynacomm"
Grid.Column="1"
Grid.ColumnSpan="1"
Text="火车售票系统后台_瞎改版"
FontFamily="华文行楷"
FontWeight="Bold"
TextAlignment="Center"
IsEnabled="True"
Background="{x:Null}"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Center"
SizeChanged="T_Dynacomm_SizeChanged"
BorderBrush="{x:Null}" SelectionBrush="{x:Null}"
>
MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
Tag="Text_EnglishDynacomm"
Grid.Column="1"
Text="Train ticketing System backstage"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Center"
FontFamily="Vivaldi" Background="{x:Null}"
BorderBrush="{x:Null}" SelectionBrush="{x:Null}"
>
Tag="Text_Account"
Text="账号:"
Grid.Column="1"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Center"
FontFamily="楷体"
FontWeight="Bold"
Background="{x:Null}"
CaretBrush="#FFD74646"
SelectionBrush="#FF266190"
BorderBrush="{x:Null}" Foreground="White"
>
Tag="TB_Account"
Text="LS007"
MouseEnter="TB_Account_MouseEnter"
Grid.Column="2"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Left"
Foreground="Gray"
TextWrapping="NoWrap"
AcceptsReturn="True" Opacity="0.7"
>
Tag="Text_Password"
Text="密码:"
Grid.Column="1"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Center"
FontFamily="楷体"
FontWeight="Bold"
Background="{x:Null}"
CaretBrush="#FFD74646"
SelectionBrush="#FF266190"
BorderBrush="{x:Null}" Foreground="White"
>
Tag="TB_Password"
Grid.Column="2"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Left"
Foreground="Gray" Opacity="0.7"
Password="990"
>
Tag="B_Login"
Content="Login"
FontFamily="Vivaldi"
Foreground="AliceBlue"
Background="SkyBlue"
Grid.Column="1"
Click="B_Login_Click">
Tag="B_Exit"
Grid.Column="3"
Content="Exit"
FontFamily="Vivaldi"
Foreground="AliceBlue"
Background="SkyBlue"
Click="B_Exit_Click">