简体   繁体   中英

Get middle row of grid to fill available space

I have been through a lot of example code for this and at the end decided to ask this : I have a grid which has a button with fixed position and another grid inside it. The outer grid has no width/height set. It should change as per the display resolution. I set W/H of window as :

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

Inside the inner grid i have 3 rows, the upper one is a button(height auto), the middle one is a listview whose height may vary (and which has to fill the available space) and the last row consists of a textbox which should remain at the bottom, of the window always. The xaml for that is below :

<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" />`

But I Just cant get the middle row to fill up the entire space and the textbox aligned at the bottom of screen. Can anyone suggest how to get the textbox aligned to bottom and the middle row to fill up the entire remaining height and How can I accomplish this without explicitly setting heights while changing display modes?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM