binding two VerticalScrollBars one to another

笑着哭i 提交于 2019-12-22 05:53:20

问题


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


回答1:


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)



来源:https://stackoverflow.com/questions/5957138/binding-two-verticalscrollbars-one-to-another

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!