简体   繁体   中英

How to get List-views to automatically adjust height when the window is re-sized in WPF

I'm having trouble getting the two ListViews to adjust their height to the containing window. I am using a GridSplitter between them. I want one ListView to shrink and one to grow when i drag the GridSplitter.

Here is the stripped down xaml code.

<Grid x:Name="Gridthing">
        <Grid.RowDefinitions>
            <RowDefinition Height="150"/>
            <RowDefinition Height="10"/>
            <RowDefinition Height="150"/> <!--bottom-->
        </Grid.RowDefinitions>
            <ListView  Name="Things1" Grid.Row="0"/>
            <GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="LightGray"></GridSplitter>
            <ListView  Name="Things2" Grid.Row="2"/>
</Grid>

However in this example the bottom ListView always 150 tall regardless of what size the window is set too.

Now I can already hear a thousand voices screaming use "*" or "auto" for the the height of the bottom grid row.

However that has a worse problem. The bottom ListView now extends passed the window and has no scroll bar, rendering anything not in the window invisible.

I am looking for a way that allows the two ListViews to take up all the space in the window with a GridSplitter in between and always displays the scroll bar.

Thanks for any help.

The Problem was that my grid was in a userconrol inside a stackpannel inside the main window. I had to swap out the stackpannel for a grid in the main window and then it performed perfectly. thanks dkozl.

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