Prevent DataGrid Scrolling From Snapping To Rows

a 夏天 提交于 2019-12-05 00:49:17

问题


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?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/11123521/prevent-datagrid-scrolling-from-snapping-to-rows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!