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

链接地址: http://www.djcxy.com/p/50072.html

上一篇: 获取一个文本框来填充WPF中的网格单元格

下一篇: 获取网格的中间行以填充可用空间