WPF 界面布局DockPanel stackPanel WrapPanel 元素内容以及位置控制

1 DockPanel

1) 默认充满整个窗口。

2) 最后一个出现的部分,默认充满剩余空间。

3) 非最后一个出现的部分,根据其中内容,进行分配空间s

 

2 StackPanel 实现居左,居右,居中 利用Margin实现

<StackPanel DockPanel.Dock="Top" Background="Red" Orientation="Vertical">
<TextBlock VerticalAlignment="Center" Margin="0,0,0,-30">Alert</TextBlock>
<Button Padding="2" Margin="0,0,0,0" HorizontalAlignment="Right" Height="30" Width="56">Click</Button>
<Button Padding="2" Margin="0,-30,0,0" HorizontalAlignment="Center" Height="30" Width="56">Click</Button>
</StackPanel>

 

 

3 位置 充分利用margin padding alingn 实现相对定位 ,元素外部利用布局控件

 


4 位置

充分利用margin padding alingn 实现相对定位 ,元素外部利用布局控件

5 元素内容控制 自动换行,滚动条,最高高度

1) 可以利用wrap maxHeight maxWidth 最大高度和内容的限制

<TextBlock TextWraping="warp" maxHeight="20">内容</TextBlock>

2) 可以利用wrap scrolViewer 滚动条 最大高度,内容不限制

<scrolViewer MaxHeight="30">
<TextBlock TextWraping="warp">内容</TextBlock>
</scrolViewer>

对于元素中的内容不确定的处理

利用Wrap属性值实现,随窗口自动伸缩换行
<TextBlock TextWrapping="Wrap">werwwrrwerwrwrr</TextBlock>

3) TextBox内容控制同上

posted @ 2014-03-28 12:42  youhumian  阅读(2979)  评论(0编辑  收藏  举报