#445 – DockPanel Can Be Used Like a StackPanel
December 7, 2011 Leave a comment
The DockPanel layout container is most often used to dock other container controls along each edge of a window and perhaps include a control that fills the remaining space. This works well as the outermost container for a main application window.
But because you can stack multiple controls consecutively on the same side, you can use a DockPanel like a StackPanel, but stacking controls in any direction.
Docking everything to the left:
Docking everything to the right:
To the top:
Or the bottom:
You can also use various combinations, stacking a series of controls to one side and then another group of controls to another side.
<DockPanel LastChildFill="False"> <Button Content="1 - Button" DockPanel.Dock="Left"/> <Button Content="2 - Button" DockPanel.Dock="Left" /> <Button Content="3 - Button" DockPanel.Dock="Left" /> <Button Content="4 - Button" DockPanel.Dock="Bottom" /> <Button Content="5 - Button" DockPanel.Dock="Bottom" /> <Button Content="6 - Button" DockPanel.Dock="Bottom" /> <Button Content="7 - Button" DockPanel.Dock="Right" /> <Button Content="8 - Button" DockPanel.Dock="Right" /> <Button Content="9 - Button" DockPanel.Dock="Right" /> </DockPanel>