How to enable scrollbar / scrolling on a WPF Datagrid

27,587

Okay, got this one figured out ... It turns out I didn't even need to wrap the datagrid around a ScrollViewer after all. All I had to do is define the height for the datagrid (Using the "Height" attribute) and the datagrid scroll bar appears when items are added that go beyond the height. Apparently when the height isn't defined it is dynamic and expands vertically as new items are added.

Another thing to add to this was that in my datagrid, I had a row details defined for each row as well, so when multiple row details were expanded, the scrolling would be enabled, but the scroll bar behavior was a little wacky (Like it wasn't smooth scrolling), and the fix for that to make it smooth scrolling was adding the following datagrid attribute: ScrollViewer.CanContentScroll="False" (I'm guessing the datagrid control is/inherits from a ScrollViewer) and then the scrolling was smooth and like the normal expected scrolling behavior.

Share:
27,587
BrianP
Author by

BrianP

Updated on November 09, 2020

Comments

  • BrianP
    BrianP over 3 years

    I've got a DataGrid control that's within a Grid layout container, and I can't seem to get the auto-scroll on the DataGrid itself to work. I can wrap the DataGrid around a ScrollViewer and thus adding the scroll bar, but the auto scrolling doesn't work.

    So right now, when new entries are added to the DataGrid, the DataGrid just expands vertically. I'd like to have the vertical scroll bar enabled allowing scrolling to the items in the DataGrid when more items are added than the original vertical size can show, instead of the whole DataGrid expanding. Surely there's got to be an easy way to make that happen.