一站式网站建设设计,网站开发语言作用,工商企业信息查询公示系统,百度网站查反链WPF布局元素有如下几个#xff1a;
Grid#xff1a;网格。可以自定义行和列并通过行列的数量、行高和列宽来调整控件的布局。StackPanel#xff1a;栈式面板。可将包含的元素在竖直或水平方向上排成一条直线#xff0c;当移除一个元素后#xff0c;后面的元素会自动向前移…WPF布局元素有如下几个
Grid网格。可以自定义行和列并通过行列的数量、行高和列宽来调整控件的布局。StackPanel栈式面板。可将包含的元素在竖直或水平方向上排成一条直线当移除一个元素后后面的元素会自动向前移动以填补空缺。Canvas画布。内部元素可以使用以像素为单位的绝对坐标进行定位类似Windows Form编程的布局方式。DockPanel泊靠式面板。内部元素可以选择泊靠方向类似于在Windows Form编程中设置控件的Dock属性。WrapPanel自动折行面板。内部元素在拍满一行后能够自动拆行。
Grid
特点
可定义任意数量的行和列行列的高宽可以使用绝对值、相对值或自动调整方式进行设定并可设置最大和最小值内部元素可以设置自己所在的行和列的位置从索引0开始还可设置跨度多少行或列可是设置Children元素的对齐方向
行列的宽高单位
计算机图形设计的标注单位是像素Pixel因此Grid的宽高单位就是像素除了像素作为单位外还可以接受英寸Inch、里面CM和点Point。 对于Grid的行高列宽我们可以设置三类值
绝对值double数值加单位后缀像素单位可以省略比例值double数值后加一个星号“ * ”自动值字符串Auto
比例值像素计算方式解析器会把所以的比例值得数值加起来作为分母把每个比例值得数值作为分子在用这个分数乘以未被占用得像素数得到得结果就是分配给这个比列值得最终像素。例如一个总高度为200px的Grid它包含5行其中两行采用绝对值50px其它三行分别为1*2*2*。则剩下为100px其三行分配的像素数分别为20px40px40px。
案列
Window x:ClassGrid_01.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:Grid_01mc:IgnorabledTitle留言板 Height240 Width440Grid Margin10Grid.RowDefinitionsRowDefinition Height20 /RowDefinition Height4/RowDefinition Height*/RowDefinition Height4/RowDefinition Height25//Grid.RowDefinitionsGrid.ColumnDefinitionsColumnDefinition WidthAuto /ColumnDefinition Width*/ColumnDefinition Width80/ColumnDefinition Width4/ColumnDefinition Width80//Grid.ColumnDefinitionsTextBlock Text请选择您的部门并留言 Grid.Column0 Grid.Row0 VerticalAlignmentCenter/ComboBox Grid.Column1 Grid.Row0 Grid.ColumnSpan4/TextBox Grid.Column0 Grid.Row2 Grid.ColumnSpan5 BorderBrushBlack/Button Content提交 Grid.Column2 Grid.Row4/Button Content清楚 Grid.Column4 Grid.Row4//Grid
/Window StackPanel
StackPanel可以把内部元素在纵向或横向紧凑排列当排在前面的元素抽掉之后排在它后面的元素会整体向前移动、补占原有元素的空间。 应用场景
同类元素需要紧凑排列如制作菜单或者列表移除其中的元素后能够自动补缺的布局或动画
属性 Orientation 决定内部元素是横向累积还是纵向累积 HorizontalAlignment 决定内部元素水平方向的排列方式 VerticalAlignment 决定内部元素竖直方向的排列方式
Canvas
Canvas布局就像在画布上画控件一样Winform开发时外面通过设置控件的Left和Top等属性来确定控件在窗体上的位置而WPF的控件没有Left和Top等属性因此当控件放在Canvas会添加位置信息。 应用场景
一经设计基本上不会再有改动的小型布局如图标需要大量使用横纵坐标进行绝对点定位的布局
WrapPanel
WrapPanel内部采用的是流式布局可以使用Orientation属性来控制流延伸的方向使用HorizontalAlignment和VerticalAlignment 两个属性控制内部控件的对齐。在流延伸的方向上WrapPanel会排列尽可能多的控件排不下的控件将会新起一行或一列继续排列。通常在上位机卡控页面会结合UniformGrid进行使用。
案例
Window x:ClassUniformGrid_04.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:UniformGrid_04mc:IgnorabledTitleMainWindow Height450 Width800UniformGrid Columns2 Rows10 Margin50,20,0,0WrapPanelTextBlock Text面积: /TextBox Width120 Height30 //WrapPanelWrapPanelTextBlock Text面积: /TextBox Width120 Height30 //WrapPanelWrapPanelTextBlock Text面积: /TextBox Width120 Height30 //WrapPanelWrapPanelTextBlock Text面积: /TextBox Width120 Height30 //WrapPanelWrapPanelTextBlock Text面积: /TextBox Width120 Height30 //WrapPanelWrapPanelTextBlock Text面积: /TextBox Width120 Height30 //WrapPanelWrapPanelTextBlock Text面积: /TextBox Width120 Height30 //WrapPanelWrapPanelTextBlock Text面积: /TextBox Width120 Height30 //WrapPanelWrapPanelTextBlock Text面积: /TextBox Width120 Height30 //WrapPanelWrapPanelTextBlock Text面积: /TextBox Width120 Height30 //WrapPanelWrapPanelTextBlock Text面积: /TextBox Width120 Height30 //WrapPanelWrapPanelTextBlock Text面积: /TextBox Width120 Height30 //WrapPanelWrapPanelTextBlock Text面积: /TextBox Width120 Height30 //WrapPanelWrapPanelTextBlock Text面积: /TextBox Width120 Height30 //WrapPanelWrapPanelTextBlock Text面积: /TextBox Width120 Height30 //WrapPanelWrapPanelTextBlock Text面积: /TextBox Width120 Height30 //WrapPanel/UniformGrid
/Window