Share via


MouseLeftButtonUp Event

Occurs when the left mouse button is released.

XAML
<object MouseLeftButtonUp="eventhandlerFunction" .../>
Scripting
[token = ]object.AddEventListener("MouseLeftButtonUp", eventhandlerFunction)

AddEventListener Parameters

token

integer

A token that is returned from the function, which you can optionally retain as a variable. If you intend to call RemoveEventListener to remove the handler, you will need this token.

eventhandlerFunction

object

The name of your event handler function as it is defined in script. When used as an AddEventListener parameter, quotes around the function name are not required. See Remarks.

Event Handler Parameters

sender

object

Identifies the object that invoked the event.

mouseEventArgs

object

mouseEventArgs.GetPosition(element).X identifies the x-coordinate position of the mouse.

mouseEventArgs.GetPosition(element).Y identifies the y-coordinate position of the mouse.

mouseEventArgs.Shift determines whether the SHIFT key is down.

mouseEventArgs.Ctrl determines whether the CTRL key is down.

Event Information

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

Remarks

The MouseLeftButtonUp event is fired when the left mouse button is released when the mouse is over the object. When the mouse is depressed, the MouseLeftButtonDown event is fired. However, if the mouse if moved over another object when it is released, the object that received the MouseLeftButtonDown event will not receive the MouseLeftButtonUp event. There is no discrete double click event. A double click is simply two sequences of MouseLeftButtonDown and MouseLeftButtonUp events.

The MouseLeftButtonUp event is a bubbling event. This means that if there multiple MouseLeftButtonUp events defined for a tree of elements, the event is received by each object in the object hierarchy, starting with the object that directly receives the event and then bubbling to each successive parent element. The "bubbling" metaphor indicates that the event starts at the bottom and works its way up the object tree. For a bubbling event, sender in the arguments is the object where the event is handled, not necessarily the object that actually received the input condition that initiated the event.

You can also add handlers in script using a quoted string for the event handler name:

object.AddEventListener("MouseLeftButtonUp", "eventhandlerFunction")

This syntax also returns a token; however, the token is not an absolute requirement for removing the handler, in cases where the handler was added by using a quoted string. For details, see RemoveEventListener.

Examples

The following XAML example illustrates bubbling and shows MouseLeftButtonUp events defined for a two Canvas and one TextBlock objects. In this case, if you release the mouse over the TextBlock object, it receives the MouseLeftButtonUp event. The event is then bubbled upward to the parent Canvas, and finally to the top-level Canvas object.

XAML
<!-- The TextBlock event occurs first. -->
<Canvas 
  xmlns="https://schemas.microsoft.com/client/2007"
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
  MouseLeftButtonUp="rootCanvasMouseLeftButtonUp">
  <Canvas Canvas.Left="20" Canvas.Top="20"
    MouseLeftButtonUp="canvasMouseLeftButtonUp">
    <TextBlock 
      x:Name="myTextBlock" 
      Canvas.Left="25" Canvas.Top="5"
      MouseLeftButtonDown="textMouseLeftButtonDown"
      FontSize="24"
      Text="Click me" />
  </Canvas>
</Canvas>

The following JavaScript example shows how to implement a MouseLeftButtonUp event handler function:

JavaScript
function rootCanvasMouseLeftButtonUp(sender, mouseEventArgs)
{
    // Set the TextBlock to display the mouse position.
    sender.findName("myTextBlock").text = "x = " + mouseEventArgs.getPosition(null).x + "  y = " + mouseEventArgs.getPosition(null).y ;
}

Applies To

Canvas, Ellipse, Glyphs, Image, InkPresenter, Line, MediaElement, Path, Polygon, Polyline, Rectangle, TextBlock

See Also

Silverlight Events
Silverlight Mouse Support
MouseEnter
MouseLeave
MouseLeftButtonDown
MouseMove
GetPosition