title: Synchronizing scroll positions for 2 WPF DataGrids
body: <p>I am trying to <strong>synchronize</strong> the horizontal <strong>scroll position</strong> of 2 <strong>WPF DataGrid</strong> controls.</p>
  
  <p>I am subscribing to the <strong>ScrollChanged</strong> event of the first DataGrid:</p>
  
  <pre><code>&lt;toolkit:DataGrid x:Name="SourceGrid" ScrollViewer.ScrollChanged="SourceGrid_ScrollChanged"&gt;
  </code></pre>
  
  <p>I have a second DataGrid:</p>
  
  <pre><code>&lt;toolkit:DataGrid x:Name="TargetGrid"&gt;
  </code></pre>
  
  <p>In the event handler I was attempting to use the <strong><code>IScrollInfo.SetHorizontalOffset</code></strong>, but alas, DataGrid doesn't expose <code>IScrollInfo</code>:</p>
  
  <pre><code>private void SourceGrid_ScrollChanged(object sender, ScrollChangedEventArgs e)
  {
      ((IScrollInfo)TargetGrid).SetHorizontalOffset(e.HorizontalOffset);
      // cast to IScrollInfo fails
  }
  </code></pre>
  
  <p>Is there another way to accomplish this? Or is there another element on TargetGrid that exposes the necessary <code>IScrollInfo</code> to achieve the synchronization of the scroll positions?</p>
  
  <p>BTW, I am <strong>using frozen columns</strong>, so I cannot wrap both DataGrid controls with ScrollViewers.</p>