设为首页
优惠IDC
收藏本站
六狼博客
六狼论坛
开启辅助访问
切换到窄版
用户名
Email
自动登录
找回密码
密码
登录
立即注册
只需一步,快速开始
只需一步,快速开始
快捷导航
门户
首页
BBS
云计算
大数据
手机
移动开发android,ios,windows phone,windows mobile
编程
编程技术java,php,python,delphi,ruby,c,c++
前端
WEB前端htmlcss,javascript,jquery,html5
数据库
数据库开发Access,mysql,oracle,sql server,MongoDB
系统
操作系统windows,linux,unix,os,RedHat,tomcat
架构
项目管理
软件设计,架构设计,面向对象,设计模式,项目管理
企业
服务
运维实战
神马
搜索
搜索
热搜:
php
java
python
ruby
hadoop
sphinx
solr
ios
android
windows
centos
本版
帖子
用户
六狼论坛
»
首页
›
编程技术
›
MicroSoft
›
WPF
›
WPF之布局
返回列表
查看:
271
|
回复:
0
WPF之布局
[复制链接]
峰顶飞龙
峰顶飞龙
当前离线
积分
30
窥视卡
雷达卡
升级
60%
当前用户组为
童生
当前积分为
30
, 升到下一级还需要 20 点。
8
主题
8
主题
8
主题
童生
童生, 积分 30, 距离下一级还需 20 积分
童生, 积分 30, 距离下一级还需 20 积分
积分
30
发消息
楼主
|
发表于 2013-1-3 15:38:23
|
显示全部楼层
|
阅读模式
<div id="cnblogs_post_body"> 此文目的旨在让人快速了解,没有什么深度,如需深入了解布局,请参考msdn。
如果你要把WPF当winform使用,拖拖控件也无不可,不过建议还是不要拖的好。
本文将那些用的比较多的几个布局控件(Grid、UniformGrid、StackPanel、WrapPanel、DockPanel以及Canvas)综合起来,布局那个伟大的乌龟。
话不多说,贴运行图和代码。
下面是XAML代码。
<div class="cnblogs_code" >
View Code <div id="cnblogs_code_open_224ba7b7-2c77-42c9-b7b7-94d90c8e6942" class="cnblogs_code_hide">
<
Window
x:Class
="LayoutPractice.MainWindow"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
Title
="MainWindow"
Height
="640"
Width
="640"
>
<
Grid
ShowGridLines
="True"
>
<
Grid.RowDefinitions
>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
/>
<
ColumnDefinition
/>
<
ColumnDefinition
/>
</
Grid.ColumnDefinitions
>
<
Grid.Resources
>
<
Style
TargetType
="Button"
>
<
Setter
Property
="Width"
Value
="60"
/>
<
Setter
Property
="Height"
Value
="60"
/>
<
Setter
Property
="Template"
>
<
Setter.Value
>
<
ControlTemplate
>
<
Border
Background
="#ff909090"
BorderBrush
="#ff707070"
BorderThickness
="1"
>
</
Border
>
</
ControlTemplate
>
</
Setter.Value
>
</
Setter
>
</
Style
>
</
Grid.Resources
>
<
StackPanel
Orientation
="Horizontal"
VerticalAlignment
="Center"
HorizontalAlignment
="Center"
Grid.Column
="3"
>
<
Button
/>
<
Button
/>
</
StackPanel
>
<
DockPanel
Width
="120"
Height
="120"
>
<
Button
DockPanel.Dock
="Top"
Width
="Auto"
Height
="30"
/>
<
Button
DockPanel.Dock
="Bottom"
Width
="Auto"
Height
="30"
/>
<
Button
DockPanel.Dock
="Left"
/>
<
Button
DockPanel.Dock
="Right"
/>
</
DockPanel
>
<
Grid
Grid.Row
="2"
VerticalAlignment
="Center"
HorizontalAlignment
="Center"
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
/>
<
ColumnDefinition
/>
<
ColumnDefinition
/>
</
Grid.ColumnDefinitions
>
<
Grid.RowDefinitions
>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
StackPanel
Grid.RowSpan
="2"
VerticalAlignment
="Center"
>
<
Button
/>
<
Button
/>
</
StackPanel
>
<
StackPanel
Grid.ColumnSpan
="2"
Grid.Row
="0"
Grid.Column
="1"
Orientation
="Horizontal"
>
<
Button
/>
<
Button
/>
</
StackPanel
>
<
StackPanel
Grid.RowSpan
="2"
Grid.Column
="2"
Grid.Row
="1"
>
<
Button
/>
<
Button
/>
</
StackPanel
>
<
StackPanel
Grid.ColumnSpan
="2"
Grid.Column
="0"
Grid.Row
="2"
Orientation
="Horizontal"
>
<
Button
/>
<
Button
/>
</
StackPanel
>
</
Grid
>
<
Grid
Grid.Row
="2"
Grid.Column
="2"
VerticalAlignment
="Center"
HorizontalAlignment
="Center"
>
<
Grid.RowDefinitions
>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
StackPanel
Orientation
="Horizontal"
HorizontalAlignment
="Center"
>
<
Button
/>
</
StackPanel
>
<
StackPanel
Grid.Row
="1"
Orientation
="Horizontal"
HorizontalAlignment
="Center"
>
<
Button
/>
<
Button
/>
</
StackPanel
>
<
StackPanel
Grid.Row
="2"
Orientation
="Horizontal"
HorizontalAlignment
="Center"
>
<
Button
/>
<
Button
/>
<
Button
/>
</
StackPanel
>
</
Grid
>
<
StackPanel
Grid.Row
="1"
Orientation
="Horizontal"
VerticalAlignment
="Center"
HorizontalAlignment
="Center"
>
<
Button
VerticalAlignment
="Bottom"
/>
<
Button
RenderTransformOrigin
="0.5 0.5"
Margin
="0 0 0 42"
>
<
Button.RenderTransform
>
<
RotateTransform
Angle
="45"
/>
</
Button.RenderTransform
>
</
Button
>
<
Button
VerticalAlignment
="Bottom"
/>
</
StackPanel
>
<
WrapPanel
Grid.Row
="1"
Grid.Column
="2"
VerticalAlignment
="Center"
HorizontalAlignment
="Center"
>
<
StackPanel
Orientation
="Horizontal"
>
<
Button
/>
<
Button
/>
<
Button
/>
</
StackPanel
>
<
StackPanel
Orientation
="Horizontal"
Margin
="60 0 0 0"
>
<
Button
HorizontalAlignment
="Center"
/>
</
StackPanel
>
<
StackPanel
Orientation
="Horizontal"
>
<
Button
/>
<
Button
/>
<
Button
/>
</
StackPanel
>
</
WrapPanel
>
<
UniformGrid
Grid.Column
="1"
Rows
="3"
Columns
="3"
VerticalAlignment
="Center"
HorizontalAlignment
="Center"
>
<
Button
/>
<
Button
/>
<
Button
/>
<
Button
/>
<
Button
/>
<
Button
/>
<
Button
/>
<
Button
/>
<
Button
/>
</
UniformGrid
>
<
Button
Grid.Row
="2"
Grid.Column
="1"
/>
<
Canvas
Grid.Row
="1"
Grid.Column
="1"
Width
="180"
Height
="180"
>
<
Button
Canvas.Left
="0"
Canvas.Top
="0"
/>
<
Button
Canvas.Right
="0"
Canvas.Top
="0"
/>
<
Button
Canvas.Left
="0"
Canvas.Bottom
="0"
/>
<
Button
Canvas.Right
="0"
Canvas.Bottom
="0"
/>
<
Button
Margin
="60"
/>
</
Canvas
>
</
Grid
>
</
Window
>
回复
使用道具
举报
提升卡
置顶卡
沉默卡
喧嚣卡
变色卡
千斤顶
显身卡
返回列表
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
|
立即注册
本版积分规则
发表回复
回帖后跳转到最后一页
Copyright © 2008-2020
六狼论坛
(https://it.6wolf.com) 版权所有 All Rights Reserved.
Powered by
Discuz!
X3.4
京ICP备14020293号-2
本网站内容均收集于互联网,如有问题请联系
QQ:389897944
予以删除
快速回复
返回顶部
返回列表