views:

11

answers:

1

If you want to get mousemove events over a group of controls in a window, it seems there are a couple of ways to do this, but none are very clean.

The hacks I've seen:

  1. Application.AddMessageFilter; Blatantly check all events coming to the window. (difficult to limit to a specific part of the program.)

  2. Recursively hook up handlers to every child control (this means you have to convert the mouse positions based on what fired the event.)

I was hoping for a simpler solution where I can subscribe to the routed event of a control, or something similar. I found mention of PreviewMouseMove, but it does not seem to be implemented in wpf? Would it be possible to accomplish this task by doing something to detect when routed events pass through the control without making any changes to the child controls or adding low level hooks? If so, please give example code.

A: 

PreviewMouseMove is an event in UIElement (msdn). You can use it, depending how you group your controls. If they're in, for example, a Panel, then you could put a PreviewMouseMove handler on the panel to keep track of mouse movements over it and all of the controls on it.

Donnie