为什么DockPanel.Dock ="Bottom"将元素放在顶部?

Edw*_*uay 14 wpf xaml dockpanel

以下代码将两个文本元素放在顶部,即使第二个文本元素标记为"Bottom".背景颜色一直到底部,所以DockPanel似乎伸展到底部.

我对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>
Run Code Online (Sandbox Code Playgroud)

rmo*_*ore 31

通过默认的一个DockPanel中的最后一个项目,将填补剩余的可用内容区域.

如果您LastChildFill="False"在DockPanel上设置,您将看到您期望的行为.您也可以VerticalAlignment="Bottom"在TextBlock上进行设置.