简体   繁体   English

在WPF中调整窗口大小时,如何获取列表视图以自动调整高度

[英]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. 我在获取两个ListView来将它们的高度调整到包含窗口时遇到麻烦。 I am using a GridSplitter between them. 我在它们之间使用了GridSplitter。 I want one ListView to shrink and one to grow when i drag the GridSplitter. 当我拖动GridSplitter时,我希望一个ListView缩小,另一个要增长。

Here is the stripped down xaml code. 这是精简的xaml代码。

<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. 但是,在此示例中,无论窗口设置的大小如何,底部的ListView始终高150。

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. 现在,底部的ListView扩展通过了窗口,并且没有滚动条,从而使窗口中看不到的所有内容都不可见。

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. 我正在寻找一种方法,该方法允许两个ListView占用窗口之间的所有空间,并在其中插入一个GridSplitter并始终显示滚动条。

Thanks for any help. 谢谢你的帮助。

The Problem was that my grid was in a userconrol inside a stackpannel inside the main window. 问题是我的网格位于主窗口内的堆栈面板内的userconrol中。 I had to swap out the stackpannel for a grid in the main window and then it performed perfectly. 我必须将堆栈面板换成主窗口中的网格,然后它才能完美运行。 thanks dkozl. 谢谢dkozl。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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