Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight
Silverlight 3
UIElement Class
UIElement Events
 MouseMove Event
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Silverlight 3

Other versions are also available for the following:
.NET Framework Class Library for Silverlight
UIElement..::.MouseMove Event

Occurs when the coordinate position of the mouse (or stylus) changes while over a UIElement (or while a UIElement holds mouse capture).

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
Public Event MouseMove As MouseEventHandler
Visual Basic (Usage)
Dim instance As UIElement
Dim handler As MouseEventHandler

AddHandler instance.MouseMove, handler
C#
public event MouseEventHandler MouseMove
XAML Attribute Usage
<uiElement MouseMove="eventhandler"/>

Be careful when you write code for a MouseMove handler. MouseMove will frequently occur while the user is interacting with the application or with the specific object area that has the handler. Any computationally or graphically intensive code in a MouseMove handler can potentially introduce a noticeable lag in how the mouse pointer (or stylus) draws and how the application generally behaves.

The MouseMove event can be handled for any UIElement-derived class, such as Canvas, TextBlock, or Rectangle.

The MouseMove event is raised in response to the mouse pointer (or stylus) moving across the object's content area. If the mouse pointer (or stylus) enters the object's content area, the MouseEnter event precedes the MouseMove event for the object. The MouseMove event is not raised if the mouse (or stylus) did not actually move. For instance, MouseMove is not raised if the mouse pointer (or stylus) remains stationary, and an object with a MouseMove handler has its position animated or otherwise adjusted to move under the mouse pointer.

A UIElement that has captured the mouse will receive MouseMove events for all movements of the mouse (or stylus), potentially including movement outside of the Silverlight content area. See "Mouse Capture" section of Mouse Support.

The MouseMove event is a bubbling event. This means that if multiple MouseMove event handlers are registered for a sequence of objects connected by parent-child relationships in the object tree, the event is received by each object in that relationship. The event is raised by the object that directly receives the input condition that initiates the event, and then bubbles to each successive parent object. The bubbling metaphor indicates that the event starts at the source and works its way up the object tree. For a bubbling event, the sender available to the event handler identifies the object where the event is handled, not necessarily the object that actually received the input condition that initiated the event. To get the object that initiated the event, use the OriginalSource value of the event's MouseEventArgs event data.

MouseMove and OnMouseMove

Controls that inherit MouseMove can provide special handling for the event, by overriding the OnMouseMove method. As with direct handling of the event, there is no Handled property available, so OnMouseMove cannot be implemented in such a way that it suppresses further handling of the event through the Handled technique. However, OnMouseMove can be useful either for setting visual state, or for state properties and behavior related to the mouse. For instance, ButtonBase implements OnMouseMove as part of a larger behavior set that makes a button click cancellable: if the user clicks the mouse on a button but then moves the mouse pointer outside the button bounds, a click is not invoked. For more information, see OnMouseMove.

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker