WPF:DockPanel中的两个控件停靠在" Top"和"底部"仍然在底部留下空间

时间:2017-08-11 11:38:22

标签: wpf dockpanel

我有简单的WPF UserControl,如下所示。

我不明白为什么这段代码没有将绿色Grid固定到DockPanel的底部: enter image description here

如果我在两个块之间添加一些东西,那么绿色固定在底部:

enter image description here

以下是简单的代码:

<UserControl
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:tWorks.Alfa.OperatorClient.UserControls.Vehicles"
         xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol" x:Class="tWorks.Alfa.OperatorClient.UserControls.Vehicles.Misc_Vehicles_GpsTrackBarContext"
         mc:Ignorable="d" 
         d:DesignHeight="260" d:DesignWidth="450">
<DockPanel>
    <Grid DockPanel.Dock="Top" Height="50" Background="Red"></Grid>
    <Grid DockPanel.Dock="Bottom" Height="50" Background="Green"></Grid>
    <Grid Height="50" Background="Blue"></Grid>
</DockPanel>

谢谢=)

1 个答案:

答案 0 :(得分:3)

您需要阻止最后一个孩子伸展:

<DockPanel LastChildFill="False"/>

否则最后一个孩子将忽略DockPanel.Dock="Bottom",而是将其放在整个剩余区域。它会在中心对齐,因为它是Height="50"

相关问题