Home Forums WPF controls Xceed DataGrid for WPF Handling ScrollChanged

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #24364 |

    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)

    User (Old forums)
    Member
    Post count: 23064

    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)

    User (Old forums)
    Member
    Post count: 23064

    Thanks, Lena, that’s just what we needed!

    Imported from legacy forums. Posted by Mark (had 3666 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.