2017-08-11 84 views
1

我有简单的WPF UserControl,如下所示。WPF:DockPanel中的两个控件停靠在“顶部”和“底部”仍然留下底部空间

我不明白为什么这个代码犯规针绿色网格的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> 

感谢=)

回答

3

您需要防止最后一个孩子从压腿:

<DockPanel LastChildFill="False"/> 

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

+0

谢谢!这是一个非常奇怪的行为。这是什么原因,人们可能会怀疑......无意义=) – Ted

+1

“原因”是一个很大的词,但是如果WPF开发者确实允许'DockPanel.Dock =“Fill”',那么我很乐意。不需要将填充元素放在最后,并将默认的Tab键排序,等等......我无法给出一个理由,只知道我自己很难学会,所以现在它相对容易回答其他问题: ) – grek40

相关问题