Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

binding two VerticalScrollBars one to another

Tags:

c#

.net

wpf

textbox

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

like image 947
Night Walker Avatar asked May 10 '11 22:05

Night Walker


1 Answers

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)

like image 146
H.B. Avatar answered Oct 21 '22 12:10

H.B.