#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>

About these ads

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

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 )

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

Follow

Get every new post delivered to your Inbox.

Join 233 other followers

%d bloggers like this: