行高设置为"自动"的WPF网格布局面板

Nat*_*ate 9 wpf grid layout

我希望网格顶部和底部有一行,其中包含标签或按钮.在中间我打算使用ListBox.我希望ListBox扩展以使用所有可用空间.不硬编码其他两行的高度会很好.我的XAML在下面.如何让中间部分自动展开?谢谢.

<UserControl x:Class="WpfApplication1.UserControl1"
         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" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>

    <Label Grid.Row="0"
           Grid.ColumnSpan="3"
           Content="Top Row" />

    <ListBox Grid.Row="1"
             Grid.ColumnSpan="3" />

    <Label Grid.Row="2"
           Grid.ColumnSpan="3"
           Content="Bottom Row" />
</Grid>
Run Code Online (Sandbox Code Playgroud)

Chr*_*l52 14

尝试将中间行设置为此...

<RowDefinition Height="*" /> 
Run Code Online (Sandbox Code Playgroud)

  • @内特。“*”快捷方式比这更复杂。在这个例子中你不需要更多的东西,但是如果你有一个复杂的网格,你需要多行或多列以不同的比例扩展,你可能有一个“2*”和另一个“5*”。如果您将它们都保留在“*”(这是说 1* 的快捷方式),那么这两行将在它们之间平均划分扩展空间。干杯 (2认同)

kiw*_*pom 5

换中间的

<RowDefinition Height="Auto" />
Run Code Online (Sandbox Code Playgroud)

<RowDefinition Height="*" />
Run Code Online (Sandbox Code Playgroud)