WPF - Making ListView (GridView) Scroll when too m

2019-05-28 19:37发布

问题:

<Grid>
  <ListView ItemsSource="....">
    <ListView.View>
      <GridView>
        <GridViewColumn ......../>
      </GridView>
    </ListView.View>
  </ListView>
</Grid>

When there are thousands of rows the above XAML causes the Grid to size larger than the form and the data becomes hidden.

What I want to do is to keep the ListView so that it fills the grid (which fills the form), and to have a vertical scrollbar to scroll through the items (leaving the header row in place at the top). Just like a WinForm grid would.

Can anyone tell me how to achieve this? I don't want to use 3rd party components.

Thanks

回答1:

Presumably your Grid is hosted in a StackPanel. Get rid of that and it should work fine.