【问题标题】:Fill DockPanel middle area by a grid用网格填充 DockPanel 中间区域
【发布时间】:2015-04-06 00:39:48
【问题描述】:

我有下面的 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>

【问题讨论】:

    标签: wpf dockpanel


    【解决方案1】:

    像这样改变:

     <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 = true默认的LastChildFill属性,这意味着Dockpanel中的最后一个孩子将填充Dockpanel,所以你可以交换红色网格和绿色网格,制作贪婪网格是 Dockpanel 的最后一个孩子。

    【讨论】:

      猜你喜欢
      • 2022-01-22
      • 2016-12-02
      • 2019-09-29
      • 2010-11-08
      • 2013-02-26
      • 2016-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多