Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does DockPanel.Dock="Bottom" put element at the top?

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>
like image 288
Edward Tanguay Avatar asked Jun 17 '09 07:06

Edward Tanguay


People also ask

How do you use dock panels?

DockPanel defines an area to arrange child elements relative to each other, either horizontally or vertically. With DockPanel you can easily dock child elements to top, bottom, right, left and center using the Dock property.

What is the difference between StackPanel and DockPanel?

StackPanel vs. For example, the order of child elements can affect their size in a DockPanel but not in a StackPanel. This is because StackPanel measures in the direction of stacking at PositiveInfinity, whereas DockPanel measures only the available size. The following example demonstrates this key difference.

What is Dock panel?

The DockPanel control defines an area where you can arrange child elements either horizontally or vertically, relative to each other. The DockPanel position child controls based on the child Dock property, you have 4 options to Dock, left (Default), right, top, bottom.

Why we use DockPanel?

DockPanel gives us an area to arrange the elements with each other. We can place the child elements either horizontally or vertically. With the help of the DockPanel, we can easily arrange the child elements at the top, bottom, right, left, and the center by using the Dock property.


1 Answers

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.

like image 175
rmoore Avatar answered Oct 19 '22 20:10

rmoore