Dock Panel
Introduction介绍
The dock panel is a layout panel, that provides an easy docking of elements to the left, right, top, bottom or center of the panel. The dock side of an element is defined by the attached property DockPanel.Dock
. To dock an element to the center of the panel, it must be the last child of the panel and the LastChildFill
property must be set to true.
WPF中的DockPanel是提供对元素进行左边停靠、右边停靠、顶部停靠、底部停靠、填充停靠操作的布局控件。每个元素的根据DockPanel.Dock属性定义本身的停靠方式。对于停靠在中间的元素,它必须子元素的最后一个,并且LiastChildFill属性设置为True.
<DockPanel LastChildFill="True">
<Button Content="Dock=Top" DockPanel.Dock="Top"/>
<Button Content="Dock=Bottom" DockPanel.Dock="Bottom"/>
<Button Content="Dock=Left"/>
<Button Content="Dock=Right" DockPanel.Dock="Right"/>
<Button Content="LastChildFill=True"/>
</DockPanel>
Multiple elements on one side多元素同时停靠
The dock panel layout supports multiple elements on one side. Just add two or more elements with the same dock side. The panel simply stacks them.
DockPanel控件支持多个元素同时停靠,只需要添加两个或两个以上的元素用同样的Dock属性即可,DockPanel将自动把控件堆放起来。
<DockPanel LastChildFill="True"> <Button Content="Dock=Left"/> <Button Content="Dock=Left"/> <Button Content="Dock=Top" DockPanel.Dock="Top"/> <Button Content="Dock=Bottom" DockPanel.Dock="Bottom"/> <Button Content="Dock=Right" DockPanel.Dock="Right"/> <Button Content="LastChildFill=True"/> </DockPanel>
Change the stacking order
The order of the elements matters. It determines the alignment of the elements. The first elements gets the whole width or height. The following elements get the remaining space.
元素的顺序很重要。它决定了元素的对齐方式。第一个元素获得了整个宽度或高度。下列元素得到的剩余空间。