Question

How to get these dockpanels right ?

<DockPanel Grid.Row="1" LastChildFill="True" HorizontalAlignment="Stretch">
    <DockPanel Width="400" LastChildFill="False" HorizontalAlignment="Left">
            <DockPanel>
                <TextBlock Width="400" />
            </DockPanel>
            <DockPanel  Height="35" DockPanel.Dock="Bottom" LastChildFill="False">
                <Button x:Name="btnRefresh" Content="Refersh" />
            </DockPanel>
    </DockPanel>

The DockPanel with the TextBlock spans over the DockPanel that is docked at the bottom, I want it to fit right up to it. Any ideas?

Ok, it turns out: the panel docked at the bottom must preceed the dockpanel above it in the xaml declaration. LastChildFill="True" applies to the control that is declared last in the code.

<DockPanel Grid.Row="1" LastChildFill="True" HorizontalAlignment="Stretch">
    <DockPanel Width="400" LastChildFill="False" HorizontalAlignment="Left">
        <DockPanel  Height="35" DockPanel.Dock="Bottom" LastChildFill="False">
            <Button x:Name="btnRefresh" Content="Refersh" />
        </DockPanel>
        <DockPanel>
            <TextBlock Width="400" />
        </DockPanel>
    </DockPanel>
Was it helpful?

Solution

Please refer to the DockPanel Class page at MSDN which has all the help that you need. The XAML example from the linked page:

<DockPanel LastChildFill="True">
    <Border Height="25" Background="SkyBlue" BorderBrush="Black" BorderThickness="1" 
        DockPanel.Dock="Top">
        <TextBlock Foreground="Black">Dock = "Top"</TextBlock>
    </Border>
    <Border Height="25" Background="Blue" BorderBrush="Black" BorderThickness="1" 
        DockPanel.Dock="Top">
        <TextBlock Foreground="White">Dock = "Top"</TextBlock>
    </Border>
    <Border Height="25" Background="Yellow" BorderBrush="Black" BorderThickness="1" 
        DockPanel.Dock="Bottom">
        <TextBlock Foreground="Black">Dock = "Bottom"</TextBlock>
    </Border>
    <Border Width="200" Background="PaleGreen" BorderBrush="Black" BorderThickness="1" 
        DockPanel.Dock="Left">
        <TextBlock Foreground="Black">Dock = "Left"</TextBlock>
    </Border>
    <Border Background="White" BorderBrush="Black" BorderThickness="1">
        <TextBlock Foreground="Black">This will fill the remaining space</TextBlock>
    </Border>
</DockPanel>

Note the use of the DockPanel.Dock attached properties.

enter image description here

OTHER TIPS

<DockPanel Grid.Row="1" LastChildFill="True" HorizontalAlignment="Stretch">
   <DockPanel Width="400" LastChildFill="False" HorizontalAlignment="Left">
       <Button x:Name="btnRefresh" Content="Refersh" 
               Height="35" DockPanel.Dock="Bottom" />

       <TextBlock Width="400" />
   </DockPanel>

   <!-- Other UI Elements here? -->

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