Detect Scrolling Event of ListBox?

前端 未结 1 1172
情歌与酒
情歌与酒 2021-01-18 22:55

Is there an event fired when a ListBox begins to scroll?

I currently have the following code to allow for a seamless drag and dropping from a listbox.



        
相关标签:
1条回答
  • 2021-01-19 00:00

    No, there is not an event fired when the ListBox scrolls, however, you can locate the ScrollViewer which is within the ListBox template and handle the ValueChanged event which occurs as soon as scrolling starts.

    You can locate the scrollbar as follows:

    /// <summary>
    /// Searches the descendants of the given element, looking for a scrollbar
    /// with the given orientation.
    /// </summary>
    private static ScrollBar GetScrollBar(FrameworkElement fe, Orientation orientation)
    {
      return fe.Descendants()
                .OfType<ScrollBar>()
                .Where(s => s.Orientation == orientation)
                .SingleOrDefault();
    
    }
    

    This uses Linq to Visual Tree, as described in this blog post.

    0 讨论(0)
提交回复
热议问题