DataGrid Scrollbar Binding

Apr 8, 2009 at 7:13 AM

I have to DataGrids in a window They both have a vertical scrollbar and if the window gets to small, they have a horizontal scrollbar too. The horizontal scrollbar shall only be visible for the second grid. when scrolling this scrollbar in the second grid, the first grid should scroll too.
I implemented this with two Scrollviewers, but the performance is going down, because the grid takes three times longer to do the databinding.
And I cannot scroll the scrollviewer with the mouseweel when I am over the grid!

Is there a way to bind the first grids Scrollbar to the one of the second grid and hide the scrollbar of the first grid?

Apr 9, 2009 at 6:11 AM
I couldn' find a way yet. The attached properties from the scrollbar on the grid only allow me to set the FlowDirection, not the offset.
Is there a way to achieve what I want with the scrollbars of the Grid or do I have to take my Scrollviewers?
The performance is sooo bad and I don't know what to do against it, so it would be great if anybody could help me with the scrollbars!
May 4, 2009 at 1:05 PM
I have found a way to get to the Scrollviewers in the DataGrid:

Here is what I have done:
ScrollViewer view1 = _erwarteteBuchungen.Template.FindName("DG_ScrollViewer", _erwarteteBuchungen) as ScrollViewer;
ScrollViewer view2 = _buchungGrid.Template.FindName("DG_ScrollViewer", _buchungGrid) as ScrollViewer;

But I still have the problem that the scrolling event is not fired when the user uses the arrow-buttons and does not drag with the mouse. Does anybody know if this is a bug or do I have to use another event for this?
May 4, 2009 at 2:23 PM
That's an interesting approach. As for your question, have you looked at the CurrentCellChanged event? It sounds like in combination with what you have, it would do nicely.
May 5, 2009 at 6:25 AM
Hi mikj!

I did not describe what I meant correctly. I mean this little buttons at the sides of the scrollbar, where you can see the little arrows on...

But your suggestion is a good one too. I did not think about the possibility that the user can use the mouse to navigate inside of the grid! There should be a binding for this too. Otherwise the grids wouldn't have the same columns visible anymore. Thanks.
May 6, 2009 at 8:37 AM
The problem is solved now.
Her is a link to a discussion where a sulotion is shown: