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>
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With