#653 – MouseMove Events

Most controls in WPF inherit a series of mouse input events from the UIElement class.  This includes the PreviewMouseMove (tunneling) and MouseMove (bubbling) events.

The MouseMove events indicate that the user is moving the mouse across the element in question.  As the user moves the mouse, the event fires for the control that the mouse is over.

Because these events propagate, however, the events will also tunnel down to the control that the mouse is over and then bubble back up the logical tree.

For example, if we have a TextBox inside a StackPanel that is inside a Window and we move the mouse around within the TextBox, we’ll see the following events fired:

  • PreviewMouseMove on Window
  • PreviewMouseMove on StackPanel
  • PreviewMouseMove on TextBox
  • MouseMove on TextBox
  • MouseMove on StackPanel
  • Mousemove on Window

 

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

3 Responses to #653 – MouseMove Events

  1. Pingback: Dew Drop – September 24, 2012 (#1,407) | Alvin Ashcraft's Morning Dew

  2. Mark Peskir says:

    Thank you for this! Very very needed for my project.

  3. Mark Peskir says:

    My project and I thank you for this. Perfect explanation of tunneling vs. bubbling.

Leave a comment