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

前端 未结 5 1755
长情又很酷
长情又很酷 2020-11-27 05:48

I have gone through the thread:

binding two VerticalScrollBars one to another

it has almost helped to achieve the goal but still there is something missing.

5条回答
  •  难免孤独
    2020-11-27 06:44

    One way to do this is using the ScrollChanged event to update the other ScrollViewer

    
        
    
    
    
        
    
    
    private void ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            if (sender == sv1)
            {
                sv2.ScrollToVerticalOffset(e.VerticalOffset);
                sv2.ScrollToHorizontalOffset(e.HorizontalOffset);
            }
            else
            {
                sv1.ScrollToVerticalOffset(e.VerticalOffset);
                sv1.ScrollToHorizontalOffset(e.HorizontalOffset);
            }
        }
    

提交回复
热议问题