如果高度设置为自动,WPF ListView 没有滚动条 [英] WPF ListView no scrollbar if height set to auto
问题描述
我有一个绑定到集合的 ListView.我将 ListView 的高度设置为 auto 使其占据该区域的所有空间.但是在我将高度设置为自动后没有滚动条.如果我给它一个高度,那么滚动条就会出现.
Hi i have a ListView that binds to a collection. I set the height of the ListView to auto for it to take up all the space in the region. However there is not scrollbar after i set the height to auto. If i give it a height then the scrollbar would show up.
标记很像下面
<Grid>
<StackPanel>
<Expander>
<DataGrid>
<Expander>
<ListView>
推荐答案
我有一种预感,您的 ListView
位于一个面板内,允许它无限制地垂直扩展.
I have a hunch that your ListView
is inside a panel that allows it to expand vertically without limit.
如果你把一个ListView
放在一个StackPanel
中,例如,ListView
的高度可以超过的高度堆栈面板
.ListView
增加了它的高度以显示它的所有项目,就它而言,因此没有滚动条.
If you put a ListView
inside a StackPanel
, for example, the ListView
's height can exceed the height of the StackPanel
. The ListView
has increased its height to show all its items, as far as it's concerned, thus no scrollbar.
但是,如果您将 StackPanel
更改为 Grid
,其中控件会自动尝试适应该区域,ListView
将自动当滚动条包含的项目多于它可以显示时,有一个滚动条.
However, if you change that StackPanel
to a Grid
, where controls automatically try to fit themselves inside that area, the ListView
will automatically have a scrollbar when it contains more items than it can display.
这可能最简单地通过调整包含 ListView
的布局来解决.
This will probably be solved most simply by adjusting your layout that contains the ListView
.
这篇关于如果高度设置为自动,WPF ListView 没有滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!