I have a DataGrid in which each row contains an ItemsControl. Because of this, the rows of the grid can be very tall. If a row is taller than the height of the grid, I'm unable to scroll to see the rest of the row because the DataGrid is automatically scrolling to the next row. That is, if I'm viewing the top half of row 1 and I click the vertical scrollbar's down arrow, it skips to the top of row 2. It doesn't let me see the bottom half of row 1. How do I make the DataGrid scroll over rows smoothly instead of stepping row by row?
Asked
Active
Viewed 3,221 times
2 Answers
8
It sound like you want to disable Virtualization. To do it, just set CanContentScroll
to False
for the ScrollViewer
. However, if you have alot of data in your DataGrid
it can become pretty slow if you turn of Virtualization since all DataGridRows
will be generated at once instead of when they're actually visible to the user.
<DataGrid ...
ScrollViewer.CanContentScroll="False">

Fredrik Hedblad
- 83,499
- 23
- 264
- 266
-
Thanks @Meleak. I tried that before and it didn't change anything but this time it's doing the trick. I do not want to disable virtualization, but what choice do I have if I want to see a whole row? Sounds like a DataGrid bug to me. Speaking of which, changing CanContentScroll to false also causes my first 29 rows to not lay out correctly the first time the grid is loaded. The rows do not expand vertically to fit their content. If I click the button to load it a second time it displays correctly. – xr280xr Jun 20 '12 at 18:29
-
I haven't seen any way to get "smooth scrolling" with virtualization enabled. About the 29 rows not loading correctly, it sounds like a weird bug you're experiencing. Can you post some code that reproduces the issue? – Fredrik Hedblad Jun 20 '12 at 18:35
7
I bumped into this problem where the scrolling would stick to rows. Then I came across: https://stackoverflow.com/a/13384164/4791472
<Datagrid ..
VirtualizingPanel.ScrollUnit="Pixel"
basically it sets the scrolling to snap to pixels instead of items. This will make for a smooth scrolling experience.

Community
- 1
- 1

Robin Grönlund
- 88
- 2
- 5