0

I have something like this:

Synchronized scrolling of two ScrollViewers whenever any one is scrolled in wpf

The problem is that the size of the content of the Scrollviewer do not have the same width.

I have managed to calculate the proportional movement of the bars but does not take into account the size of the bars, which are different from each other:

sv2.ScrollToHorizontalOffset(e.HorizontalOffset * (sv1.Width / grid1.Width) / (sv2.Width / grid2.Width));

sv1.ScrollToHorizontalOffset(e.HorizontalOffset * (sv2.Width / grid2.Width) / (sv1.Width / grid1.Width));

enter image description here

It only coordinates the start of the bars, regardless of their size. Any ideas?

imj
  • 472
  • 1
  • 8
  • 24
  • And what result exactly you expect? Synchronize the ends of the bars? But then you won't like that start of bars are not syncrhonized. Maybe synchronize the centers? – Evk May 23 '18 at 07:41

1 Answers1

1

You have to calculate the scrolling position in a fraction of the total:

After scrolloffset on sv1 changes try something like

var scFract = sv1.HorizontalOffset / sv1.ScrollableWith;
sv2.ScrollToHorizontalOffset(sv2.ScrollableWith * scFract);
Seididieci
  • 404
  • 4
  • 14