通过网格填充DockPanel中间区域

时间:2015-02-05 23:43:22

标签: wpf dockpanel

我在XAML之下,我想让中间网格(绿色网格)填充顶部蓝色和底部红色网格之间的所有区域。请帮我设置

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" SizeToContent="WidthAndHeight">
<DockPanel MinWidth="600" Background="Gold">
    <Grid DockPanel.Dock="Top" Background="Blue" Height="30"></Grid>
    <Grid DockPanel.Dock="Top" Background="Chartreuse" MinHeight="100" VerticalAlignment="Stretch"></Grid>
    <Grid DockPanel.Dock="Bottom" Background="Red" Height="10" VerticalAlignment="Bottom"></Grid>
</DockPanel>

1 个答案:

答案 0 :(得分:3)

像这样改变:

 <DockPanel MinWidth="600" Background="Gold">
    <Grid DockPanel.Dock="Top" Background="Blue" Height="30"></Grid>
    <Grid DockPanel.Dock="Bottom" Background="Red" Height="10" VerticalAlignment="Bottom"></Grid>
    <Grid DockPanel.Dock="Top" Background="Chartreuse" MinHeight="100" VerticalAlignment="Stretch"></Grid>
</DockPanel>

默认情况下,您应该知道LastChildFill的{​​{1}}属性,DockPanel,这意味着Dockpanel中的最后一个子项将填充Dockpanel,因此您可以更换红色网格和绿色网格,使贪婪网格成为Dockpanel的最后一个孩子。