/// <summary> /// This is the command scroll adjustment code which synchronizes two ScrollViewer instances. /// </summary> /// <param name="sv">ScrollViewer to adjust</param> /// <param name="e">Change in the source</param> /// <param name="hadjust">Horizontal adjustment</param> /// <param name="vadjust">Vertical adjustment</param> private static void AdjustScrollPosition(ScrollViewer sv, ScrollChangedEventArgs e, double hadjust, double vadjust) { if (e.HorizontalChange != 0 || e.ExtentWidthChange != 0) { if (e.HorizontalOffset == 0) sv.ScrollToLeftEnd(); else if (e.HorizontalOffset >= e.ExtentWidth-5) sv.ScrollToRightEnd(); else if (e.ExtentWidth + hadjust == sv.ExtentWidth) sv.ScrollToHorizontalOffset(e.HorizontalOffset + hadjust); else sv.ScrollToHorizontalOffset((sv.ExtentWidth * (e.HorizontalOffset / e.ExtentWidth)) + hadjust); } if (e.VerticalChange != 0 || e.ExtentHeightChange != 0) { if (e.VerticalOffset == 0) sv.ScrollToTop(); else if (e.VerticalOffset >= e.ExtentHeight-5) sv.ScrollToBottom(); else if (e.ExtentHeight + vadjust == sv.ExtentHeight) sv.ScrollToVerticalOffset(e.VerticalOffset + vadjust); else sv.ScrollToVerticalOffset((sv.ExtentHeight * (e.VerticalOffset / e.ExtentHeight)) + vadjust); } }
internal static void ResetScrollPositions( ScrollViewer scrollViewer ) { if( scrollViewer == null ) { throw new ArgumentNullException( "scrollViewer" ); } DataGridScrollViewer dataGridScrollViewer = scrollViewer as DataGridScrollViewer; if( dataGridScrollViewer != null ) { foreach( SynchronizedScrollViewer ssv in dataGridScrollViewer.SynchronizedScrollViewers ) { ssv.ScrollToTop(); ssv.ScrollToLeftEnd(); } } scrollViewer.ScrollToTop(); scrollViewer.ScrollToLeftEnd(); }