I have two datagrids side by side bound to different data tables and each with their own view.
The datatables both have the same number of rows, and I want both grids to maintain the same scroll position.
I am having trouble finding a way to do this using MVVM... anyone have any ideas?
Thanks! -Steven
Take a look at codeproject Scroll Synchronization
The Scroll Synchronization project doesn't work for Datagrid because it doesn't expose ScrollToVerticalOffset
I was able to overcome this issue via some reflection hacks:
and the code itself is:
The best way I've used so far is to use the
VisualTreeHelper
class to find the correctScrollViewer
object (grid or no grid). I've used this in several projects.Try this if any of you need it:
Note: I typically use ListBox classes and would pass it directly to this function.
Happy programming :)