WPF:停靠在“顶部”和“底部”的 DockPanel 中的两个控件仍然在底部留有空间

泰德

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

我不明白为什么这段代码没有将绿色网格固定到 DockPanel 的底部: 在此处输入图片说明

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

在此处输入图片说明

这是简单的代码:

<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>

谢谢=)

希腊语40

你需要防止最后一个孩子伸展:

<DockPanel LastChildFill="False"/>

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章