How to enable scrollbar / scrolling on a WPF Datagrid
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.
BrianP
Updated on November 09, 2020Comments
-
BrianP over 3 years
I've got a
DataGrid
control that's within aGrid
layout container, and I can't seem to get the auto-scroll on theDataGrid
itself to work. I can wrap theDataGrid
around aScrollViewer
and thus adding the scroll bar, but the auto scrolling doesn't work.So right now, when new entries are added to the
DataGrid
, theDataGrid
just expands vertically. I'd like to have the vertical scroll bar enabled allowing scrolling to the items in theDataGrid
when more items are added than the original vertical size can show, instead of the wholeDataGrid
expanding. Surely there's got to be an easy way to make that happen.