WPF学习笔记系列之一 (布局详情)
布局:
StackPanel 栈布局:控件不会拐弯且多出的不再显示。
DockPanel 停靠布局 吸在上边下边或左右。
WrapPanel 环绕布局 一行控件会拐弯
Canvas 进行基于坐标的布局
Grid中若不指定Grid.Row属性及Grid.Column则默认为:0行,0列。RowDefinitions ColumnDefinitions ShowGridLines=true
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
ColumnDefinition Width="*"></ColumnDefinition>
<Grid.RowDefinitions>
<RowDefinition Height="*"> </RowDefinition>
</Grid.RowDefinitions>
布局舍入:
如果一个窗体的两个部分被分正好要分一个像素就会使边框分开而不清楚,使用Grid 的UseLayoutRounding 属性设置为true就可以。
跨越多行多列:
Grid.RowSpan="n" Grid.ColumnSpan="n"
<Grid ShowGridLines="true">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*">
</ColumnDefinition>
<ColumnDefinition Width="Auto">
</ColumnDefinition>
<ColumnDefinition Width="Auto">
</ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBox Margin="10" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3">This is a test.</TextBox>
<Button Margin="10,10,2,10" Padding="3" Grid.Row="1" Grid.Column="1">OK</Button>
<Button Margin="2,10,10,10" Padding="3" Grid.Row="1" Grid.Column="2">Cancel</Button>
</Grid>
Grid中使用GridSplitter分隔条使用原则:
1. 若要非和别的控件放在一个单元格中就要调整好边距,以使它们不重叠。更好的方法是预留一列或一行专门放置GridSplitter并将预留行或列的Heigh 或Width属性值设置为Auto。
2. GridSplitter对象总是改变整行或整列的尺寸(而不是改变单个单元格的尺寸) 为了使GridSplitter对象的外观和其行为一致,需要拉伸GridSplitter 对象使其穿越整行或整列,而不是将其限制在一个单元格中,为此,可以使用RowSpan或ColumnSpan
3. 太小不可见要设置高宽长,若竖直的则设置为:VerticalAlignment="Stretch" Width="10" 横的则:HorizontalAlignment="Center"
例子如下:
<Grid ShowGridLines="true">
<Grid.RowDefinitions>
<RowDefinition ></RowDefinition>
<RowDefinition ></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100">
</ColumnDefinition>
<ColumnDefinition Width="Auto">
</ColumnDefinition>
<ColumnDefinition Width="50">
</ColumnDefinition>
</Grid.ColumnDefinitions>
<!--<TextBox Margin="10" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3">This is a test.</TextBox>-->
<Button Margin="3" Grid.Row="0" Grid.Column="0">左</Button>
<Button Margin="3" Grid.Row="0" Grid.Column="2">右</Button>
<Button Margin="3" Grid.Row="1" Grid.Column="0">左</Button>
<Button Margin="3" Grid.Row="1" Grid.Column="2">右</Button>
<GridSplitter Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" Width="3" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Center" ShowsPreview="True"></GridSplitter>
</Grid>
ShowsPreview="True" ShowPreview GridSplitter的属性,当设置为false时当你拖动时马上就看到效果,而为true是就只显示你托运的阴影直到放开鼠标。
一个Grid中多个GridSplitter代码如下:
<Window x:Class="StudyWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="孙业宝学习WPF开始" Height="350" Width="525">
<!--This is the Grid for the entire window. -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition ></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<!--This is the nested Grid on the left.It isn't subdivided further with a splitter.-->
<Grid Grid.Column="0" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition ></RowDefinition>
<RowDefinition ></RowDefinition>
</Grid.RowDefinitions>
<Button Margin="3" Grid.Row="0" >左上</Button>
<Button Margin="3" Grid.Row="1">左下</Button>
</Grid>
<!--this is the vertical splitter that sits between the two nested(left and right) grids.-->
<GridSplitter Grid.Column="1" Width="3" HorizontalAlignment="Center" VerticalAlignment="Stretch" ShowsPreview="false"></GridSplitter>
<!-- This is the nested Grid on the right. -->
<Grid Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition ></RowDefinition>
</Grid.RowDefinitions>
<Button Margin="3" Grid.Row="0">右上</Button>
<Button Margin="3" Grid.Row="2">右下</Button>
<!-- This is the horizontal splitter that subdivides it into a top and botton region.. -->
<GridSplitter Grid.Row="1" Height="3" HorizontalAlignment="Stretch " ShowsPreview="false"></GridSplitter>
</Grid>
</Grid>
</Window>
共享尺寸组:也就是两个不同的grid可以设置其两个列宽度相同通过设置Grid的 Grid.IsSharedSizeScope=true; 且把想要使用共享尺寸组的列的SharedSizeGroup="相同的名称" 例子代码如下:
<Grid Grid.IsSharedSizeScope="True" Margin="3">
<Grid Margin="3" BackGround="LightYellow" ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="TextLabel" ></ColumnDefinition>
<ColumnDefinition Width="Auto" ></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Margin="5"> A very long bit of text</Label>
<Label Grid.Column="1" Margin="5" >More Text</Label>
<TextBox Grid.Column="2" Margin="5" >A text box</TextBox>
</Grid>
<Grid Margin="3" BackGround="LightYellow" ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="TextLabel">
</ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grdi.ColumnDefinitinos>
<Label Margin="5" >Short</Lable>
<TextBox Grid.Column="1" Margin="5" >A text box</TextBox>
</Grid>
WPF学习笔记系列之一 (布局详情)的更多相关文章
- WPF学习笔记一之布局
1.Canvas 布局控件Canvas主要用来画图,注意Canvas.Left/Right/Top/Bottom <Canvas Margin="10,10,10,10" B ...
- $《利用Python进行数据分析》学习笔记系列——IPython
本文主要介绍IPython这样一个交互工具的基本用法. 1. 简介 IPython是<利用Python进行数据分析>一书中主要用到的Python开发环境,简单来说是对原生python交互环 ...
- amazeui学习笔记--css(布局相关3)--辅助类Utility
amazeui学习笔记--css(布局相关3)--辅助类Utility 一.总结 1.元素清除浮动: 添加 am-cf 这个 class 即可 2.水平滚动: .am-scrollable-horiz ...
- WPF编游戏系列 之一 布局设计
原文:WPF编游戏系列 之一 布局设计 本系列主要使用WPF和C#编写一个简单的小游戏(暂命名XMarket),意在通过该实例进一步学习和体验WPF,也欢迎广大同仁拍砖交流.言归正传,在 ...
- MongoDB学习笔记系列
回到占占推荐博客索引 该来的总会来的,Ef,Redis,MVC甚至Sqlserver都有了自己的系列,MongoDB没有理由不去整理一下,这个系列都是平时在项目开发时总结出来的,希望可以为各位一些帮助 ...
- Dynamic CRM 2013学习笔记 系列汇总
这里列出所有 Dynamic CRM 2013学习笔记 系列文章,方便大家查阅.有任何建议.意见.需要,欢迎大家提交评论一起讨论. 本文原文地址: Dynamic CRM 2013学习笔记 系列汇总 ...
- SQLServer学习笔记系列3
一.写在前面的话 今天又是双休啦!生活依然再继续,当你停下来的时候,或许会突然显得不自在.有时候,看到一种东西,你会发现原来在这个社会上,优秀的人很多,默默 吃苦努力奋斗的人也多!星期五早上按时上班, ...
- SQLServer学习笔记系列2
一.写在前面的话 继上一次SQLServer学习笔记系列1http://www.cnblogs.com/liupeng61624/p/4354983.html以后,继续学习Sqlserver,一步一步 ...
- Dynamic CRM 2015学习笔记 系列汇总
这里列出所有 Dynamic CRM 2015学习笔记 系列文章,方便大家查阅.有任何建议.意见.需要,欢迎大家提交评论一起讨论. 本文原文地址:Dynamic CRM 2015学习笔记 系列汇总 一 ...
随机推荐
- liunx 安装工具总结
1 下载相关文件,比如hadoop 2 解压文件 tar -zxcf xxx.tar.gz 3 mv xxx 到指定目录:通常安装到/usr/local 或者自己建个目录 /usr/develo ...
- Java 学习 day01
1. 基本常识 2. Java的跨平台性 3. Java环境搭建(安装) 4. Java环境搭建(环境变量配置) 5. Java环境搭建(环境变量配置技巧) 6. Java环境搭建(环境变量临时配置方 ...
- 前后端分离之fiddler前端开发代理 autoresponder 正则表达式 regex:(?insx) 修正符详解
regex:(?isx)^http://127.0.0.1:3000(/dlscene)?/order/(\w*) http://127.0.0.1:8080/dlscene/order/$2 上面这 ...
- vue element-ui 自动获取光标
<el-input ref="customerInput"></el-input> this.$refs.mark.$el.querySelector('i ...
- gridcontrol 之标题 GroupPanel设置 (标题设置,屏蔽右键)
GroupPanel设置 例如gridcontrol显示标题:“gridcontrol小例子” gridView1.GroupPanelText="gridcontrol小例子"; ...
- Android笔记之ViewModel的使用示例
依赖 implementation 'android.arch.lifecycle:extensions:1.1.1' implementation 'com.squareup.retrofit2:r ...
- 我的Android进阶之旅------>报 error: Apostrophe not preceded by \ 的错误解决办法
今天对项目进行国际化翻译的时候控制台出现了以下的错误: res/values/strings.xml:100: error: Apostrophe not preceded by \ (in Sorr ...
- Mac下php版本不支持imagetfftext函数问题
brew rm freetype jpeg libpng gd zlib brew install freetype jpeg libpng gd zlib brew install php71 ht ...
- spring-boot5代码
App.java package com.kfit.spring_boot_mybatis; import org.mybatis.spring.annotation.MapperScan; impo ...
- 创建blog APP
声明:此Django分类下的教程是追梦人物所有,地址http://www.jianshu.com/u/f0c09f959299,本人写在此只是为了巩固复习使用 什么是APP呢,Django里的APP其 ...