WPF ListView 如果高度设置为自动则没有滚动条
您好,我有一个绑定到集合的 ListView。我将 ListView 的高度设置为 auto,以使其占据该区域中的所有空间。但是,将高度设置为自动后,没有滚动条。如果我给它一个高度,那么滚动条就会显示出来。
标记非常类似于以下内容
<Grid>
<StackPanel>
<Expander>
<DataGrid>
<Expander>
<ListView>
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.
the markup is pretty much like the following
<Grid>
<StackPanel>
<Expander>
<DataGrid>
<Expander>
<ListView>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有一种预感,您的
ListView
位于一个面板内,允许它无限制地垂直扩展。例如,如果将
ListView
放入StackPanel
中,ListView
的高度可能会超过StackPanel
的高度代码>.ListView
增加了其高度以显示其所有项目(就其而言),因此没有滚动条。但是,如果您将该
StackPanel
更改为Grid
,其中控件会自动尝试将自身调整到该区域内,ListView
将自动具有滚动条当它包含的项目多于它可以显示的数量时。通过调整包含
ListView
的布局,可能可以最简单地解决此问题。I have a hunch that your
ListView
is inside a panel that allows it to expand vertically without limit.If you put a
ListView
inside aStackPanel
, for example, theListView
's height can exceed the height of theStackPanel
. TheListView
has increased its height to show all its items, as far as it's concerned, thus no scrollbar.However, if you change that
StackPanel
to aGrid
, where controls automatically try to fit themselves inside that area, theListView
will automatically have a scrollbar when it contains more items than it can display.This will probably be solved most simply by adjusting your layout that contains the
ListView
.而不是设置
集:
Instead of setting
set:
如果没有什么可滚动的,为什么要显示滚动条?
如果您想覆盖任何默认行为,可以在 ListBox 上设置
ScrollViewer.VerticalScrollBarVisibility="Visible"
。Why should it show a scrollbar if there is nothing to scroll?
If you want to override any default behavior you can set
ScrollViewer.VerticalScrollBarVisibility="Visible"
on the ListBox.