Saturday, December 9

Synchronizing the ListViews

As you remember, I am developing a .NET project which display gantt graphs.
As we start to develope the UI part we decide we need our view to be devided into two parts: text and graph. This is the same as Microsoft Project view.

Since we need both views to display header on the top and row for each activity in the gantt we decide to use WPF ListView control. ListView inhreit from ListBox and add switchable View property as well as other features.

I will not go into details about the implementation of the ListViews here, what I would like to concentrate now is how can we synchronize the vertical scroll-bar of the two lists.

We decide that the verical scroll bar of the text view should be hidden while the vertical scroll bar of the graph view should be visible. This way we need to scroll the text view list when-ever the graph view is scroll.

After much experements and trail-and-error tests I come up with the following solution: I will walk the visual tree of the two ListViews, grab and save the reference to both ListView's ScrollViewer internal element and use it to synchronize the ListViews.

I have also consulte Microsoft WPF Development Team members and they confirm my solution is the best they can think of as of this moment.

I have written a class called ItemsControlVerticalSynchornizer which synchronize the vertical scrollbar of ItemsControl, or any dervied class. I will upload the class to this post as soon as possible.

Hope you enjoy,