2つのスクロールビューアを同期させたい。両方のscrollviewerのスクロールイベントを取得して、両方を同期する方法を教えてください。
質問する
692 次
1 に答える
5
First get the 2 scrollbars of the scrollviewers you want to sync.
In this case, scrollviewer1
and scrollviewer2
Then we get event handlers of both the scrollbars, in this case vertical. Then we can easily sync them through the events. The ScrollToVerticalOffset
will scroll as per the other one does.
ScrollBar vertical1 = ((FrameworkElement)VisualTreeHelper.GetChild(scrollviewer1, 0)).FindName("VerticalScrollBar") as ScrollBar;
vertical1.ValueChanged += new RoutedPropertyChangedEventHandler<double>(vertical1_ValueChanged);
ScrollBar vertical2 = ((FrameworkElement)VisualTreeHelper.GetChild(scrollviewer2, 0)).FindName("VerticalScrollBar") as ScrollBar;
vertical2.ValueChanged += new RoutedPropertyChangedEventHandler<double>(vertical2_ValueChanged);
void vertical1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
scrollviewer2.ScrollToVerticalOffset(e.NewValue);
}
void vertical2_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
scrollviewer1.ScrollToVerticalOffset(e.NewValue);
}
Hope this helps!
于 2012-06-01T11:41:18.123 に答える