生活随笔
收集整理的這篇文章主要介紹了
WPF-常用布局容器
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
| 名稱 | 描述 |
| StackPanel | 在水平或垂直的堆棧中放置元素,通常應(yīng)用于一個復(fù)雜的布局中的一小塊區(qū)域 |
| WrapPanel | 在一系列可換行(列)的行中放置元素,支持水平、垂直方向,一行(列)放不下自動拍到下一行(列) |
| DockPanel | 根據(jù)容器整個邊界調(diào)整元素,指定上、下、左、右 |
| Grid | 網(wǎng)格布局,指定行列,經(jīng)常使用 |
| UniformGrid | 在一個不可見但是強(qiáng)制所有單元格具有相同尺寸的網(wǎng)格中放置元素,不經(jīng)常用 |
| Canvas | 使用固定坐標(biāo)絕對定位,不太常用 |
所有這些布局容器都繼承于System.Windows.Controls.Panel
1、StackPanel
| 名稱 | 描述 |
| Orientation(Horizontal、Vertical) | 布局方向:水平與垂直 |
| HorizontalAlignment、VerticalAlignment | 水平方向:Center、Left、Right、Stretch 垂直方向:Center、Top、Bottom、Stretch 該屬性決定元素在容器中靠左還是靠右還是居中 |
| Margin="5,5,5,5" | 容器周圍的控件,左、上、右、下 |
| MinWidth與MinHeight | 設(shè)置最小寬度與高度 |
| MaxWidth與MaxHeight | 設(shè)置最大寬度與高度 ? ? ? ? ? ? ? |
[html]?view plaincopy
<StackPanel?Orientation="Vertical"??VerticalAlignment="Center"?Margin="5,5,5,5"?MinHeight="50"?MinWidth="100"?MaxWidth="600"?MaxHeight="300"?Height="200"?Width="400">?? ????????????<Button?Content="Hello?World1"?MinWidth="50"?MaxWidth="100"></Button>?? ????????????<Button?Content="Hello?World2"?MinWidth="50"?MaxWidth="100"></Button>?? ????????????<Button?Content="Hello?World3"?MinWidth="50"?MaxWidth="100"></Button>?? ????????????<Button?Content="Hello?World4"?MinWidth="50"?MaxWidth="100"></Button>?? ????????????<Button?Content="Hello?World5"?MinWidth="50"?MaxWidth="100"></Button>?? ????????????<Button?Content="Hello?World6"?MinWidth="50"?MaxWidth="100"></Button>?? ????????</StackPanel>??
2、WrapPanel
[html]?view plaincopy
<WrapPanel?Orientation="Horizontal"??VerticalAlignment="Center"?Margin="5,5,5,5"?MinHeight="50"?MinWidth="100"?MaxWidth="600"?MaxHeight="300"?Height="200"?Width="400">?? ???????????<Button?Content="Hello?World1"?MinWidth="50"?MaxWidth="100"></Button>?? ???????????<Button?Content="Hello?World2"?MinWidth="50"?MaxWidth="100"></Button>?? ???????????<Button?Content="Hello?World3"?MinWidth="50"?MaxWidth="100"></Button>?? ???????????<Button?Content="Hello?World4"?MinWidth="50"?MaxWidth="100"></Button>?? ???????????<Button?Content="Hello?World5"?MinWidth="50"?MaxWidth="100"></Button>?? ???????????<Button?Content="Hello?World6"?MinWidth="50"?MaxWidth="100"></Button>?? ???????</WrapPanel>??
指定水平、垂直方向
3、DockPanel
[html]?view plaincopy
<DockPanel>?? ???????????<Menu?DockPanel.Dock="Top">?? ???????????????<MenuItem?Header="文件"></MenuItem>?? ???????????????<MenuItem?Header="編輯"></MenuItem>?? ???????????</Menu>?? ???????????<TextBox?DockPanel.Dock="Bottom"></TextBox>?? ???????</DockPanel>??
指定上下左右
4、Grid
[html]?view plaincopy
<Grid?ShowGridLines="True"?MinHeight="200"?MinWidth="400">?? ???????<Grid.RowDefinitions>?? ???????????<RowDefinition?Height="40"></RowDefinition>?? ???????????<RowDefinition></RowDefinition>?? ???????????<RowDefinition></RowDefinition>?? ???????</Grid.RowDefinitions>?? ???????<Grid.ColumnDefinitions>?? ???????????<ColumnDefinition?Width="100"></ColumnDefinition>?? ???????????<ColumnDefinition></ColumnDefinition>?? ???????????<ColumnDefinition></ColumnDefinition>?? ???????</Grid.ColumnDefinitions>?? ???????<Button?Content="第一行第一列"??Height="40"?Width="100"?Grid.Row="0"?Grid.Column="0"?MinHeight="40"?MinWidth="100"></Button>?? ???????<Button?Content="第一行第二列(跨兩列)"??Height="40"?Width="150"?Grid.Row="0"?Grid.Column="1"?Grid.ColumnSpan="2"?MinHeight="40"?MinWidth="150"></Button>?? ???</Grid>??
5、UniformGrid
[html]?view plaincopy
<UniformGrid?Rows="2"?Columns="2">?? ?????????<Button?Content="Hello(0,0)"?Margin="10,10,10,10"></Button>?? ?????????<Button?Content="Hello(0,1)"?Margin="10,10,10,10"></Button>?? ?????????<Button?Content="Hello(1,0)"?Margin="10,10,10,10"></Button>?? ?????????<Button?Content="Hello(1,1)"?Margin="10,10,10,10"></Button>?? ?????</UniformGrid>??
每一個網(wǎng)格大小一樣
6、Canvas
[html]?view plaincopy
<Canvas>?? ????????????<Button?Canvas.Left="10"?Canvas.Top="10"?Content="(10,10)"></Button>?? ????????????<Button?Canvas.Left="30"?Canvas.Top="30"?Content="(30,30)"></Button>?? ????????????<Button?Canvas.Left="100"?Canvas.Top="60"?Content="(100,60)"></Button>?? ????????</Canvas>??
總結(jié)
以上是生活随笔為你收集整理的WPF-常用布局容器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。