We need to handle the ScrollChanged event on the grid. We’re doing it now this way:
ScrollViewer sv = ourGrid.Template.FindName(“PART_ScrollViewer”, ourGrid) as ScrollViewer; sv.ScrollChanged += new ScrollChangedEventHandler(ScrollChanged);
The problem is that the event handler doesn’t “stick.” It appears that the grid periodically recreates its internal scroll viewer, and our event ends up referencing an old scrollviewer the grid isn’t using anymore — the event handler doesn’t get called anymore. It appears to happen when the DataGridCollectionView refreshes, so we’ve partially worked around the program by re-acquiring the scrollviewer and reattaching the event after each explicit dcgv.Refresh() in our code. But other things trigger these refreshes, like updating an item in our bound collection, and trying to track down each case is frustrating.
We also tried a brute-force approach where we re-acquire the scollviewer every time the app is idling and reattaching the event, but FindName seems rather slow and the app is very sluggish with this approach.
Is there a reliable way of keeping our ScrollChanged connected?
Imported from legacy forums. Posted by Mark (had 637 views)
You can create Style for ScrollViewer in resources, and in this style define <EventSetter Event=”ScrollChanged” Handler=”ScrollChanged”/> And then, in C# code have your handler (named ScrollChanged, of cource) to do what you want it to do. Good Luck! Lena
Imported from legacy forums. Posted by Lena (had 432 views)