当前位置: 首页 > news >正文

WPF之布局

1、StackPanel布局作用:依次排列,默认垂直排序,里面有个属性Orientation可以控制是水平依次排序还是垂直依次排序

2、Grid:表格布局

默认情况下是一行一列的grid,我们可以动态分配多行多列,来达到我们的布局效果

行列是可以动态增加的,元素是可以归属于某一行列的

布局中的宽度和高度,除了通过Height= "60"直接赋值外,还可以按照比例分配,例如3*,表示的是按照比例为3来自动分配,还可以通过设置AUTO,如:Height= "AUTO",表示根据里面内容,自动调整;

3、网格布局,设置多行,下面一个设计了三行  ShowGridLines="true"属性能够显示网格布局的线条

<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>

下面代码,用于向网格布局中增加控件,控件位置可以选择任意行列

<Button Grid.Column="0" Width="40" Height="40" HorizontalAlignment="Left" />

效果图:

对应的xmal文件:【重要思想:通过grid进行模块分层设计,通过stackPanel进行自动依次排序】

<Window x:Class="Clock.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:Clock"mc:Ignorable="d"Title="入门WPF" Height="450" Width="800"  WindowStartupLocation="CenterScreen"><Grid ShowGridLines="true" ><Grid.RowDefinitions><RowDefinition Height="30"/><RowDefinition Height="30"/><RowDefinition/><RowDefinition Height="30"/></Grid.RowDefinitions><StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal"  ><Button Height="25" Width="70" Content="文件"/><Button Height="25" Width="70" Content="编辑"/><Button Height="25" Width="70" Content="查看"/><Button Height="25" Width="70" Content="外观"/><Button Height="25" Width="70" Content="设置"/><Button Height="25" Width="70" Content="帮助"/></StackPanel><StackPanel Grid.Column="0" Grid.Row="1" Orientation="Horizontal"  ><Button Height="25" Width="30" Content="1"/><Button Height="25" Width="30" Content="2"/><Button Height="25" Width="30" Content="3"/><Button Height="25" Width="30" Content="4"/><Button Height="25" Width="30" Content="5"/><Button Height="25" Width="30" Content="6"/></StackPanel><!--第三行加入grid布局,然后在grid里再增加两列--><Grid Grid.Row="2" Grid.Column="0" ShowGridLines="true" ><Grid.ColumnDefinitions><ColumnDefinition Width="50"/><ColumnDefinition />  </Grid.ColumnDefinitions><StackPanel Grid.Row="0" Grid.Column="0"><Button Height="30" Width="40" Content="1"/><Button Height="30" Width="40" Content="2"/><Button Height="30" Width="40" Content="3"/><Button Height="30" Width="40" Content="4"/><Button Height="30" Width="40" Content="5"/></StackPanel><TextBox Grid.Row="0" Grid.Column="1" TextWrapping="Wrap"/></Grid><!--<Button Grid.Column="0" Grid.Row="0" Width="40" Height="40" HorizontalAlignment="Left"/><Button Grid.Column="0" Width="40" Height="40" HorizontalAlignment="Left" Margin="53,0,0,0"/>--></Grid>
</Window>

http://www.dtcms.com/a/529848.html

相关文章:

  • AD9361通信平台--AGC 原理(二)
  • 网站制作费用入什么科目龙文国土局漳滨村新农村建设网站
  • 社交网站 设计wordpress设计笔记
  • C_OBJ#_INTCOL#坏块导致数据库无法open故障处理---惜分飞
  • 如何建设网站 知乎图书馆网站建设的意义
  • 网站综合营销方案企业营销策略分析论文
  • 企业建站公司哪里找认养农业app模式定制开发
  • 网站建设前端技术网站关键词优化排名怎么做
  • 两个男生如何做网站代理网页是干什么的
  • 做app模板网站有哪些内容南沙高端网站建设
  • 红酒公司的网站建设WordPress插件手动
  • Agentic RL: 大模型后训练 SFT、PPO和GRPO
  • 织梦城市门户网站模板廊坊优化外包
  • 有些网站做不了seo背景视频素材下载免费
  • 聊城专业做网站怎样在华为云服务器里建设网站
  • 做网站为什么要用源码跳舞游戏做的广告视频网站
  • 网站建设的常用软件有哪些企业网站开发需求分析
  • 做商务网站住房与城乡建设部网站建造师
  • zk详细问题
  • 做任务得得q币的网站应用公园制作app教程视频
  • 【Linux】输入输出管理
  • 做购物网站的初衷建设网站有哪些好处和坏处
  • 从stc8g1k08+433MHZ无线点亮led 到stc8k1k17+433MHZ唯一配对并点亮小灯(过程问题总结)
  • 区域综合实验
  • 环保网站建设多少钱安徽池州建设厅网站
  • 搅拌机东莞网站建设技术支持河北邯郸特色美食
  • 将有序数组转换为二叉搜索树
  • 长春做网站公司长春seo公司网页设计师培训费用图片
  • 外贸网站 源wordpress rpc
  • 深圳建站服务中心火车头采集器和wordpress