Programmatically accessing the DataGrid ScrollViewer

Nov 17, 2008 at 11:27 PM
I need to programmatically access the DataGrid's ScrollViewer to set the scroll position (I am stacking 2 DataGrids to get freeze panes).

The only way I have found so far is to traverse the visual tree until I find the DG_ScrollViewer element. Is there a better way to do this without modifying the source code (and exposing the ScrollViewer publicly)?

Nov 18, 2008 at 12:50 PM
ScrollViewer is public so there is no need to modify product source code.  Traversing the tree is a normal way of doing it if its not provided by the control's APIs.
Jun 25, 2013 at 10:22 PM
This is a great solution. Worked fine for me in WPF.

I just made a reference to ScrollSynchronizer dll, added a xml import:


then just added this to both my datagrids and bobs your uncle:
     <Style TargetType="ScrollViewer">
         <Setter Property="scroll:ScrollSynchronizer.ScrollGroup" Value="Group1" />