用网格填充 DockPanel 中间区域
Fill DockPanel middle area by a grid
我有以下 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>
改成这样:
<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>
你应该知道默认情况下DockPanel
的LastChildFill
属性,LastChildFill = true
,这意味着Dockpanel中的最后一个child将填充Dockpanel,所以你可以交换红色网格和绿色网格,使贪婪网格是最后一个 child 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>
改成这样:
<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>
你应该知道默认情况下DockPanel
的LastChildFill
属性,LastChildFill = true
,这意味着Dockpanel中的最后一个child将填充Dockpanel,所以你可以交换红色网格和绿色网格,使贪婪网格是最后一个 child Dockpanel.