首页 文章

获取中间一行网格以填充可用空间

提问于
浏览
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 回答

  • 0

    如果你不告诉 Grid 占用所有可用空间它不能分发它,你应该将 GridVerticalAlignment 设置为 Stetch .

相关问题