日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

WPF-常用布局容器

發布時間:2025/6/15 asp.net 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WPF-常用布局容器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
名稱描述
StackPanel水平或垂直的堆棧中放置元素,通常應用于一個復雜的布局中的一小塊區域
WrapPanel在一系列可換行(列)的行中放置元素,支持水平、垂直方向,一行(列)放不下自動拍到下一行(列)
DockPanel根據容器整個邊界調整元素,指定上、下、左、右
Grid網格布局,指定行列,經常使用
UniformGrid在一個不可見但是強制所有單元格具有相同尺寸的網格中放置元素,不經常用
Canvas使用固定坐標絕對定位,不太常用
所有這些布局容器都繼承于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設置最小寬度與高度
MaxWidth與MaxHeight設置最大寬度與高度 ? ? ? ? ? ? ?
[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>??

  • 每一個網格大小一樣


    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>??
  • 總結

    以上是生活随笔為你收集整理的WPF-常用布局容器的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。