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.
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.