6

I have two TextBoxes in the control , and I have in both of thems two VerticalScrollBar. I want to bind the VerticalScrollBars between them , if one goes up the secound will go also etc... Is it possible if so how i can do it ?

Thanks

Night Walker
  • 20,638
  • 52
  • 151
  • 228

1 Answers1

8

Not a real binding but it works:

<TextBox Name="scrlTB1" Height="100" ScrollBar.Scroll="Scroll" ScrollViewer.VerticalScrollBarVisibility="Visible"/>
<TextBox Name="scrlTB2" Height="100" ScrollBar.Scroll="Scroll" ScrollViewer.VerticalScrollBarVisibility="Visible"/>
private void Scroll(object sender, ScrollEventArgs e)
{
    if (sender == scrlTB1)
    {
        scrlTB2.ScrollToVerticalOffset(e.NewValue);
    }
    else
    {
        scrlTB1.ScrollToVerticalOffset(e.NewValue);
    }
}

(This example ignores the possibility of horizontal scrolling)

H.B.
  • 166,899
  • 29
  • 327
  • 400
  • Worked with a minor adjustment: I had to change ScrollEventArgs -> System.Windows.Controls.Primitives.ScrollEventArgs e – Michael Meritt Jan 07 '16 at 20:21
  • works better for all cases https://stackoverflow.com/questions/15151974/synchronized-scrolling-of-two-scrollviewers-whenever-any-one-is-scrolled-in-wpf – Juan Pablo Gomez Jun 04 '18 at 18:35