#402 – Final Child of DockPanel Fills Remaining Space by Default

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>

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: