用dw做的企业网站,微信代运营是什么意思,建设银行行号网站查询是什么,微端网站开发WPF中布局控件继承Panel#xff0c;可以实现非常复杂的布局。我们介绍一下常用的布局控件1. Grid 布局控件Grid是网格布局控件#xff0c;在WPF开发中我们用的最多的一个布局控件#xff0c;可以自定义行和列#xff0c;分别设置Height和Witdh值#xff0c;一般推荐通过比…WPF中布局控件继承Panel可以实现非常复杂的布局。我们介绍一下常用的布局控件 1. Grid 布局控件Grid是网格布局控件在WPF开发中我们用的最多的一个布局控件可以自定义行和列分别设置Height和Witdh值一般推荐通过比例来设置这里介绍一个WPF中的知识点附件属性:我们从名字可以理解是附加给别人。Grid.Row和Grid.Column就是附加属性这两个属性本来是不属于Button对象的我们可以通过Grid.Row和Grid.Column来控制Button位置也可以Grid.RowSpan和Grid.ColumnSpan实现跨行和跨列。Window x:ClassExample_02.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:Example_02mc:IgnorabledTitleMainWindow Height600 Width800GridGrid.RowDefinitionsRowDefinition Height0.25*/RowDefinitionRowDefinition Height0.25*/RowDefinitionRowDefinition Height0.25*/RowDefinitionRowDefinition Height0.25*/RowDefinition/Grid.RowDefinitionsGrid.ColumnDefinitionsColumnDefinition Width0.5*/ColumnDefinitionColumnDefinition Width0.5*/ColumnDefinition/Grid.ColumnDefinitionsButton Grid.Row0 Grid.Column0 MaxWidth300 Width200 MinWidth30 BackgroundYellow Content第一行第一列/ButtonButton Grid.Row0 Grid.Column1 BackgroundAliceBlue Content第一行第二列/ButtonButton Grid.Row1 Grid.Column0 BackgroundAquamarine Content第二行第一列/ButtonButton Grid.Row1 Grid.Column1 BackgroundSeaGreen Content第二行第二列/ButtonButton Grid.Row2 Grid.Column0 BackgroundLemonChiffon Content第三行第一列/ButtonButton Grid.Row2 Grid.Column1 BackgroundLightBlue Content第三行第二列/Button/Grid
/Window2. StackPanel 布局控件StackPanel 是将元素排列成水平或者垂直一行。StackPanel 的Orientation默认是Vertical水平平铺我们可以设置Horizontal垂直平铺HorizontalAlignment 属性让控件水平方向处于Center、Left、Right、Stretch VerticalAlignment 属性让控件垂直方向处于Top、Center、Bottom、Stretch设置OrientationHorizontal3. DockPanel 布局控件DockPanel 控件类似于Winform中控件的Dock属性,可以将内容布局到4个方向TopLeftBottomRight。DockPanel.DockTop该控件会占据顶部的所有空间DockPanel.DockLeft该控件会占据除顶部空间以为的左侧空间DockPanel.DockBottom该控件占据除左侧空间以外的下部所有空间DockPanel.DockRight 该控件占据除上侧和下侧以外的所有右边空间设置DockPaneld的LastChildFillTrue最后一个控件将填充剩下空间我们可以从整个控件的布局能看出放进去的先后顺序.4. WrapPanel布局控件WrapPanel 在不使用行和列,可以让元素水平和垂直方向固定。在空间不足会自动换行。设置Orientation为Vertical5. Canvas 画布Canvas是通过绝对坐标x和y来定位内容, Canvas四个附加属性Canvas.Left和Canvas.Top和Canvas.Right 和 Canvas.Bottom如果坐标区域重合会产生重叠后面对象覆盖前面可以通过设置Panel.ZIndex附加属性来实现重叠中分层顺序的显示Canvas的默认行为是允许在父Canvas的边界之外绘制子级。我们可以通过设置ClipToBounds属性设置为 true超出边界 Canvas对元素进行剪裁6. VirtualizingStackPanelVirtualizingStackPanel是StackPanel的变体该控件支持对数据绑定的虚拟化配合ListBox 或 ListView进行使用, 对数据加载能有很大提升。上面介绍了WPF UI六大布局面板另外还可以配合使用装饰控件可以达到一个非常美观的效果。