DockPanel: Docking panel
DockPanel defines an area in which you can arrange child elements to be arranged as strokes, which are located in the Children property. Docking panels are similar to the dock properties of controls in WinForm. DockPanel will sort each child element and will dock according to the specified edge, and multiple elements docked on the same side are sorted sequentially. In DockPanel, controls that specify docking edges occupy corners according to the defined order, and all controls never overlap.
By default, elements that are added later can only use the remaining space, and the child element will always fill the remaining space, regardless of any docking value set on the last child element of DockPanel. If you do not want the last element to fill the remaining area, you can set the DockPanel property LastChildFill to False, and you must explicitly specify the docking direction for the last child element.
1. Fill the remaining space
Using XAML code implementations:
1<window x:class="Wpfdemo.mainwindow"2xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"3xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"4title="dockpanel Panel"height="237"Width="525"windowstartuplocation="Centerscreen">5<DockPanel>6<button dockpanel.dock=" Left"Content="Buttonleft"></Button>7<button dockpanel.dock="Top"Content="Buttontop"></Button>8<button dockpanel.dock=" Right"Content="Buttonright"></Button>9<button dockpanel.dock="Bottom"Content="Buttonbottom"></Button>Ten<button content="Buttontop"></Button> One</DockPanel> A</Window>
2, the last element does not fill the remaining space
Using XAML code implementations:
1<window x:class="Wpfdemo.mainwindow"2xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"3xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"4title="dockpanel Panel"height="237"Width="525"windowstartuplocation="Centerscreen">5<dockpanel lastchildfill="False">6<button dockpanel.dock=" Left"Content="Buttonleft"></Button>7<button dockpanel.dock="Top"Content="Buttontop"></Button>8<button dockpanel.dock=" Right"Content="Buttonright"></Button>9<button dockpanel.dock="Bottom"Content="Buttonbottom"></Button>Ten<button dockpanel.dock="Top"Content="Last button does not fill the remaining space"></Button> One</DockPanel> A</Window>
WPF tutorial four; layout dockpanel panel