Search code examples
wpfdatagridonscroll

OnScrollShow event at DataGrid WPF


How to handle scroll showing event at DataGrid?

I tried to find some solutions, but there is no one.


Solution

  • That DataGrid class does not have an OnScrollShow event. You can handle ScrollViewer.ScrollChanged for when the scroll changes. If you are more specific about what you are trying to accomplish then perhaps we can suggest how you can try to implement the functionality you desire.

    In order to detect if the scroll bar is showing, you can hook into the LayoutUpdated event and use the code in this answer to detect which scrollbars are visible:

    ScrollViewer scrollview = FindVisualChild<ScrollViewer>(dataGrid);
    Visibility verticalVisibility = scrollview.ComputedVerticalScrollBarVisibility;
    Visibility horizontalVisibility = scrollview.ComputedHorizontalScrollBarVisibility;