WPF ListView no scrollbar if height set to auto

2019-01-25 03:25发布

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>

3条回答
Fickle 薄情
2楼-- · 2019-01-25 03:50

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.

查看更多
We Are One
3楼-- · 2019-01-25 03:57

Instead of setting

<RowDefinition Height="auto"/>

set:

<RowDefinition Height="1*"/>
查看更多
Evening l夕情丶
4楼-- · 2019-01-25 04:05

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 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.

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.

This will probably be solved most simply by adjusting your layout that contains the ListView.

查看更多
登录 后发表回答