I have below XAML, I want to make the middle Grid (the green one) to fill all the area between the top Blue and the bottom Red grids. Please help me to set it up
<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>
Change like this:
<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>
You should know that for the LastChildFill
property of DockPanel
, LastChildFill = true
is the default: it means the last child in a Dockpanel will fill the Dockpanel, so you can exchange the red grid and the green grid, making the green grid the last child of the Dockpanel.