Question

In a UserControl I have:

<Grid>
        <DockPanel Grid.Column="0"
                   LastChildFill="True">
            <Label x:Name="ProductName"
                   HorizontalAlignment="Stretch"
                   DockPanel.Dock="Top"
                   Background="Red"
                   Height="60" />
            <Label x:Name="Versie"
                   HorizontalAlignment="Stretch"
                   DockPanel.Dock="Top"
                   Background="Green"
                   Height="20" />
            <Label x:Name="Copyright"
                   HorizontalAlignment="Stretch"
                   DockPanel.Dock="Top"
                   Background="Blue"
                   Height="20" />
            <Label x:Name="Company"
                   HorizontalAlignment="Stretch"
                   DockPanel.Dock="Top"
                   Background="Yellow"
                   Height="20" />
            <Label x:Name="Omschrijving"
                   HorizontalAlignment="Stretch"
                   **--> Answer: add this: VerticalAlignment="Stretch"**
                   Background="Tomato"/>
        </DockPanel>
    </Grid>

I expected that the last label would fill the available vertical space in the dockpanel/grid, because of LastChildFill="True". Its height however is a default 'auto' of 10, it doesn't fill.
The last label does not respond to DockPanel.Dock which I suppose is ok and a result of LastChildFill="True".

What can I do to make the heigth fill the remaining height?

Was it helpful?

Solution

The last label fills to fit the remaining space in the DockPanel; however, the problem is that your DockPanel currently only takes up the space required by its children.

If the main grid has space to offer, setting VerticalAlignment="Stretch" in your DockPanel will stretch the DockPanel to take up all the vertical space it can, and the last label will do that in turn.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top