15

以下代码将两个文本元素放在顶部,即使第二个被标记为“底部”。背景颜色一直到底部,因此 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>
4

1 回答 1

33

默认情况下,DockPanel 的最后一项将填充剩余的可用内容区域。

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

于 2009-06-17T08:02:46.310 回答