Site Logo


Exploring Frontend Development with Design / Graphics / Technology

Making the Scrollbar work (with DragDropManager)

This post is a corollary to a set of posts I did on the DragDropManager component.

If you have been using the DragDropManager with a ListBox, you may have encountered an issue where you are not able to scroll using the ScrollBar. There are couple of reasons for this:

  1. I have setup Preview events on the UI control on which you attached the DragDropManager. This traps all the mouse events happening on the control.
  2. When you try to use the ScrollBar to scroll, the DnD manager comes in and checks if a Drag-gesture is being made. This traps the mouse events for the ScrollBar and hence it never sees it. This is the default behavior since the ScrollViewer is part of the ControlTemplate for the ListBox and hence considered part of the control.
  3. When the PreviewMouseLeftButtonDown event occurs, the dragged-element that is returned turns out to be the ListBox itself and not the ListBoxItem or ContentPresenter (in case of a Databound ListBox). Thus it is not clear from the dragged-element, whether the MouseDown event happened on the ScrollBar or the List item.

So what’s the workaround?

The main reason the Scrollbar doesn’t work is because of it being part of the ControlTemplate. Hence we need to take it out. We can then put the ListBox inside a ScrollViewer separately and get the desired scrolling behavior. Now the mouse preview events do not include the ScrollBar anymore.

A side note

I have improved the DragDropManager and made some changes to the IDragSourceAdvisor and IDropTargetAdvisor interfaces. Will make a post on that soon :)

Making the Scrollbar work (with DragDropManager)
Pavan Podila
Pavan Podila
July 2nd, 2007