怎么做网站滑动图片部分,百度账号登录个人中心,租空间网站,长春星宿网站建设公司怎么样今天我来给大家讲解在学习WPF过程中使用布局控件的一些心得#xff0c;主要给大家介绍一下一个控件的用法。希望对大家学习Wpf有所帮助.
1. StackPanel栈面板
2. WrapPanel环绕面板
3. DockPanel停靠面板
4. Grid网格
5. UniformGrid均布网…今天我来给大家讲解在学习WPF过程中使用布局控件的一些心得主要给大家介绍一下一个控件的用法。希望对大家学习Wpf有所帮助.
1. StackPanel栈面板
2. WrapPanel环绕面板
3. DockPanel停靠面板
4. Grid网格
5. UniformGrid均布网格
6. Canvas画布 1. StackPanel栈面板
栈面板是WPF中最简单的面板用来在小范围内布局效果非常好。将它包含的元素按一行或者一列进行排列.StackPanel内的元素不会换行。如果stackPanel内没有足够的空间它内部的元素超过了它所容纳的范围时内部元素将被截取。
通过设置Orientation属性为Horizontal, Vertical
可以使stackpanel内部的元素水平或垂直排列关于这点用户可以自己试验
效果图如下 代码 Window x:ClassWpfPanel.MainWindow xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml TitleMainWindow Height367 Width505 Grid StackPanel Margin0 NamestackPanel1 OrientationVertical Button ContentButton Namebutton1 / Button ContentButton Namebutton2 / Button ContentButton Namebutton3 / Button ContentButton Namebutton4 / Button ContentButton Namebutton5 / /StackPanel /Grid
/Window
. 通过设置stackpanel内部控件的VerticalAlignment属性可以设置其内部控件的排列方式。
当StackPanel属性为OrientationHorizontal,可以设置内部控件的VerticalAlignment来设置其对齐方式
当StackPanel属性为Orientation Vertical ,可以设置内部控件的HorizontalAlignment来设置其对齐方式
效果图 代码
Window x:ClassWpfPanel.MainWindow xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml TitleMainWindow Height367 Width505 Grid StackPanel Margin0 NamestackPanel1 OrientationHorizontal Button ContentButton1 Namebutton1 VerticalAlignmentTop / Button ContentButton2 Namebutton2 VerticalAlignmentBottom/ Button ContentButton3 Namebutton3 VerticalAlignmentCenter / Button ContentButton4 Namebutton4 VerticalAlignmentStretch / Button ContentButton5 Namebutton5 VerticalAlignmentTop / /StackPanel /Grid
/Window
2. WrapPanel环绕面板
Wrappanel面板的使用和stackpanel面板一样但是如果wrappanel面板内部没有足够的空间其子元素超出了其内部可容纳的宽度可以换行显示.
效果图: 代码
Window x:ClassWpfPanel.wrappanelOne xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml TitlewrappanelOne Height300 Width300 Grid WrapPanel Height100 HorizontalAlignmentLeft Margin30,82,0,0 NamewrapPanel1 VerticalAlignmentTop Button ContentButton Height23 Namebutton1 Width75 / Button ContentButton Height23 Namebutton2 Width75 / Button ContentButton Height23 Namebutton3 Width75 / Button ContentButton Height23 Namebutton4 Width75 / /WrapPanel /Grid
/Window
3. Dockpanel布局面板
Dockpanel面板主要用来拉伸其内部控件并使控件停靠在内部的某个位置主要用来做整体布局设计使用。
Dockpanel提供了四个属性用来设置其内部控件布局
Left:位于DOCKPANEL左侧的子元素
Top:位于DOCKPANEL顶部的子元素
Right:位于DOCKPANEL右侧的子元素
BUTTON位于DOCKPANLE底部的子元素.
效果图 代码
Window x:ClassWpfPanel.dockpanelOne xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml TitledockpanelOne Height300 Width300 Grid DockPanel NamedockPanel1 Button Content顶£¤部? Namebutton1 DockPanel.DockTop/ Button Content左Á¨®侧¨¤ Namebutton2 DockPanel.DockLeft/ Button Content右®¨°侧¨¤ Namebutton3 DockPanel.DockRight / Button Content底Ì¡Á部? Height23 Namebutton4 DockPanel.DockBottom / Button Content剩º¡ê余®¨¤空?间? Namebutton5/ /DockPanel /Grid
/Window 如果将DOCKPANEL的LastChildFillFalse则最后一个子元素不会占满剩余空间,默认情况下为true
效果图 代码 Window x:ClassWpfPanel.dockpanelOne xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml TitledockpanelOne Height300 Width300 Grid DockPanel NamedockPanel1 LastChildFillFalse Button Content顶£¤部? Namebutton1 DockPanel.DockTop/ Button Content左Á¨®侧¨¤ Namebutton2 DockPanel.DockLeft/ Button Content右®¨°侧¨¤ Namebutton3 DockPanel.DockRight / Button Content底Ì¡Á部? Height23 Namebutton4 DockPanel.DockBottom / Button Content剩º¡ê余®¨¤空?间? Namebutton5/ /DockPanel /Grid
/Window
当然你可以设置其内部的元素的HorizontalAlignment和VerticalAlignment属性来具体设置其内部排列方式,读者可以自己试验 demo下载http://download.csdn.net/source/2474542
在下 一节中我们将为大家讲解其他控件的用法