WPF主要的6个布局分别是什么
开发工具与关键技术:PLSQL Developer + DML
作者:琉敏
撰写时间:2019年5月1日
什么是WPF?
WPF(Windows Presentation Foundation)是微软推出的基于Windows 的用户界面框架,属于.NET Framework 3.0的一部分。它提供了统一的编程模型、语言和框架,真正做到了分离界面设计人员与开发人员的工作;同时它提供了全新的多媒体交互用户图形界面。
WPF的6个布局分别是哪6个?
WPF中主要的6个布局分别是: StackPanel(栈式面板)、WrapPanel(环绕面板)。DockPanel(停靠面板)、Canvas(画布)、Grid(网格面板)和UniformGrid(均布网格)。
1、 StackPanel:栈式面板
栈式面板的特点是:每一个元素都是占满一行或一列,占满一行或一列主要是由属性(Orientation)决定的,当属性(Orientation)是Vertical时,它是垂直占满一行的(图a);当属性(Orientation)是Horizontal时,它是水平占满一列的(图b)。
(1)使用XAML代码实现:
<Window x:Class="Wpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="StackPanel面板" Height="220" Width="400" WindowStartupLocation="CenterScreen">
//<!--stackpanel面板:栈式面板-->
<StackPanel x:Name="stackpanel" Orientation="Vertical">
<Button Content="第一个栈式面板"></Button>
<Button Content="第二个栈式面板"></Button>
<Button Content="第三个栈式面板"></Button>
</StackPanel>
</Window>
(2)垂直方向排列界面运行效果:
2、 WrapPanel:环绕面板
环绕面板的特点是:将各个控件从左至右按照行或列的顺序罗列,当剩余空间不够时会自动换行或换列。主要是由属性(Orientation)决定的,当属性(Orientation)是Vertical时,它是垂直方向从左到右排列的(图c);当属性(Orientation)是Horizontal时,它是水平方向从左到右排列的(图d)。
(1) 使用XAML代码实现:
<Window x:Class="Wpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WrapPanel面板" Height="220" Width="430" WindowStartupLocation="CenterScreen">
//<!--wrappanel:环绕面板-->
<WrapPanel x:Name="WrapPanel" Orientation