Question

The following code puts the two text elements at the top even though the second one is marked "Bottom". The background color goes all the way to the bottom so the DockPanel seems to stretch to the bottom.

What am I not understanding about DockPanel?

<Window x:Class="TestIndexer934.Views.MainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c="clr-namespace:TestIndexer934.Commands"
    Title="Main Window" Height="400" Width="800">
    <DockPanel HorizontalAlignment="Left" Background="Beige">
        <TextBlock DockPanel.Dock="Top" Text="Testing top"/>
        <TextBlock DockPanel.Dock="Bottom" Text="Testing bottom"/>
    </DockPanel>
</Window>
Was it helpful?

Solution

By default a DockPanel's last item will fill the remaining content area available.

If you set LastChildFill="False" on the DockPanel, you'll see the behavior you are expecting. You can also set VerticalAlignment="Bottom" on the TextBlock.

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