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

时间:2009-06-17 07:55:25

标签: 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>

1 个答案:

答案 0 :(得分:31)

通过default,DockPanel的最后一项将填充剩余的可用内容区域。

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

相关问题