使网格的中间行填充可用空间

6

我浏览了很多相关示例代码,最终决定询问以下问题:我有一个网格,其中有一个固定位置的按钮和另一个网格。外层网格未设置宽度/高度。它应该根据显示分辨率进行更改。我将窗口的W/H设置为:

Width = 200;
Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - 5;

在内部网格中,我有3行,上面一行是一个按钮(高度自适应),中间一行是一个列表视图,其高度可能会变化(并且必须填充可用空间),最后一行由一个文本框组成,它应始终保留在窗口底部。以下是该XAML:

<Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Click="Button_Click" Width="32" Height="32" FontSize="16" VerticalAlignment="Center" 
            HorizontalAlignment="Left" FontWeight="Bold" ToolTip="Click here to hide the Sidebar">&gt;</Button>
<Grid VerticalAlignment="Top" Background="Transparent" Grid.Row="1">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <!-- This is the settings bar-->
            <RowDefinition Height="*" />
            <!-- This will contain the listbox-->
            <RowDefinition Height="Auto" />
            <!-- This is to maintain vertical arrangement and future use-->
        </Grid.RowDefinitions>

        <Button Content="hello" Grid.Row="0" />
        <ListView x:Name="lstView" Background="Transparent" Grid.Row="1"/>
        <TextBox TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="50" Margin="2" BorderBrush="Black" Grid.Row="2" />`

但是我无法让中间行填满整个空间,文本框对齐在屏幕底部。有人可以建议如何使文本框对齐到底部,中间行填满剩余的高度,并且如何在更改显示模式时不显式设置高度来实现这一点?


1
你所拥有的 RowDefinition 确实会使第二行在此 Grid 中占据所有剩余空间。现在你需要查看它的父级,并确保该父级允许此 Grid 填充整个窗口。我看到你的 Grid 上有一个 Grid.Row,因此父级可能是另一个 Grid;那么它的 RowDefinition 是什么样子的呢? - Joe White
我在那个网格上没有添加任何网格定义,我只是用它在窗口中央添加了一个固定按钮...没有其他用途... - Dannyboy
1个回答

0

如果您不告诉Grid占用所有可用空间,则无法将其分配,您应该将GridVerticalAlignment设置为Stretch


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接