Share via


UIElement.MouseLeftButtonDown Event

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Occurs when the left mouse button is pressed (or when the tip of the stylus touches the tablet) while the mouse pointer is over a UIElement.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Event MouseLeftButtonDown As MouseButtonEventHandler
public event MouseButtonEventHandler MouseLeftButtonDown
<uiElement MouseLeftButtonDown="eventhandler"/>

Remarks

The MouseLeftButtonDown event is raised when the left mouse button is pressed (or when the tip of the stylus touches the tablet PC) while the mouse pointer is over the UIElement. When the mouse button (or the tip of the stylus) is released, the MouseLeftButtonUp event is raised. However, if the mouse pointer (or the stylus) is moved over another object when the button is released, the UIElement that received the MouseLeftButtonDown event will only receive the MouseLeftButtonUp event if that UI element has explicitly captured the mouse. There is no discrete double-click event. A double-click consists of two sequences of MouseLeftButtonDown and MouseLeftButtonUp events. Click count can be captured using event data (ClickCount).

Use a handler based on MouseButtonEventHandler to handle this event. For more information on how to handle mouse events, see Mouse Support.

Mouse capture is a concept whereby an object can continue to receive mouse events, even if the mouse pointer (or the stylus) is no longer over the object's bounding area. In order to request mouse capture, the mouse left button (or the stylus) must be in a pressed (down) state. Therefore, a common point in code to call CaptureMouse is from within the MouseLeftButtonDown handler for a particular UIElement. For more information on mouse capture and scenarios where it is useful, see Mouse Support or How to: Drag and Drop Objects in UI Layout.

Routed Event Behavior

The MouseLeftButtonDown event is a bubbling event. This means that if multiple MouseLeftButtonDown 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 bubbling metaphor indicates that the event starts at the object that directly receives the input condition, 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 RoutedEventArgs event data.

MouseLeftButtonDown and OnMouseLeftButtonDown

Controls that inherit MouseLeftButtonDown can provide handling for the event that acts as handler for all instances, by overriding the OnMouseLeftButtonDown method. This might include marking the Handled value of the event as true, which has the effect of suppressing the MouseLeftButtonDown event on any instance of the control (and potentially any subclass of the control). For instance, ButtonBase implements OnMouseLeftButtonDown in such a way that the mouse left button captures the mouse and raises the ButtonBase-defined Click event. The implementation also sets Handled, which generally prevents mouse button actions from being reported as a MouseLeftButtonDown event that could be handled by a button instance. This is done because the Click event is more meaningful for the control's intended purpose. For more information, see OnMouseLeftButtonDown.

You can also register handlers such that they are invoked even for already-handled routed events. For more information, see AddHandler.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

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