如果高度设置为自动,WPF ListView 没有滚动条 [英] WPF ListView no scrollbar if height set to auto

查看:82
本文介绍了如果高度设置为自动,WPF ListView 没有滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定到集合的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆