#402 – Final Child of DockPanel Fills Remaining Space by Default
October 6, 2011 Leave a comment
By default, the last child in the list of child elements of a DockPanel will automatically grow to fill the available space, regardless of the value of the DockPanel.Dock property.
<DockPanel> <Label Content="1st label (Top)" DockPanel.Dock="Top" Background="Bisque"/> <Label Content="2nd (Left)" DockPanel.Dock="Left" Background="BurlyWood"/> <Label Content="3rd fills remaining space" DockPanel.Dock="Top" Background="Cornsilk"/> </DockPanel>
This happens because the DockPanel has a property called LastChildFill that defaults to true. If we set it to false, we can then dock the last child element–and it will not fill all of the available space.
<DockPanel LastChildFill="False"> <Label Content="1st label (Top)" DockPanel.Dock="Top" Background="Bisque"/> <Label Content="2nd (Left)" DockPanel.Dock="Left" Background="BurlyWood"/> <Label Content="3rd fills remaining space" DockPanel.Dock="Top" Background="Cornsilk"/> </DockPanel>