tags:

views:

135

answers:

1

I'm building a special listbox control that our designers want customized in some tweaky ways.

One thing they want to see is that the middle button-drag does what the left button-drag normally does (we are repurposing left-drag to other things).

So it needs the two key features that left-drag does in a ListBox default implementation:

  1. While holding down the button and dragging, the selection starts where I click down and extends to where I drag.
  2. While dragging outside the listbox region, it scrolls if there is scrollable space in that direction.

Before I go an duplicate this functionality by hand, is there any easy way to fool ListBox into thinking it's getting left-mouse drag events but instead is getting middle-mouse?

A: 

MouseDown will help you. It monitors all mice. Here's a good article on it. http://blogs.msdn.com/b/nickkramer/archive/2005/06/13/428754.aspx

from the article:

We have MouseLeftButtonDown and MouseRightButtonDown events, but no MouseMiddleButtonDown event. You can get at the middle button by using the attached event Mouse.MouseDown, which listens to all mouse buttons, and check for args.ChangedButton == MouseButton.Middle.

Christopher Estep
Oh, and let me add that there's no baked-in way to use the middle-mouse button.
Christopher Estep
My question wasn't about how to get middle-mouse events, it was about how to remap the middle-mouse events that I capture over to left-mouse events that I can pass to the listbox.
Scott Bilas
The ListBox doesn't automatically implement drag and drop so I'm uncertain what you're asking then.WPF gives a framework for you to hook up for drag and drop, but there's no property you can turn on or event that you just hook that automatically handles the dragging. You still need to capture the mousedown , or rather PreviewMouseDown. Whatever code you would put in for the left button can go there and use the event argument to determine that it is the middle button being caught.Here is how to do that: http://diptimayapatra.wordpress.com/2010/01/16/drag-and-drop-item-in-listbox-in-wpf/
Christopher Estep
I'm not after drag and drop, I'm after the drag-select. Say you have a listbox with 1000 items in it. You click down somewhere and start dragging outside of the listbox area. The listbox responds by starting a selection where you click down, extending it to the edge of the listbox, and then sets up a timer to scroll the box until it reaches the end, extending the selection as it goes. I need it to do that with the middle button instead of left.
Scott Bilas