Reputation: 1217
I am having an issue with MouseLeftButtonUp
not firing when I press my left mouse button down on one UIElement
(i.e. a Rectangle
) then move my mouse to another Rectangle
and release the left mouse button.
According to this page http://msdn.microsoft.com/en-us/library/system.windows.uielement.mouseleftbuttonup.aspx it is because the event only fires when on the same element that the left mouse button was pressed down on,
Occurs when the left mouse button is released while the mouse pointer is over this element.
How can this problem be solved?
I tried adding a Grid element beneath both Rectangles to handle the MouseLeftButtonUp event and that didn't seem to solve the problem. When moving from Rect to Rect it doesn't fire, but when moving from Rect to Grid it fires. When moving from Grid to Rect it doesn't fire either. Different bubbling strategy?
Here is what I'm working with. Examine the second column where each Rectangle is YELLOW. They have been 'highlighted' by pressing on the top rectangle and dragging down to the bottom Rectangle. Once reaching the bottom rectangle I would like to be able to have the mouse button up event occur (by any means) to perform some action.. doesn't work!
If this seems like a weird solution to this type of 'highlight' mechanic or flat-out misuse of Rectangle in this situation don't be shy to say so, I'm new to WP8.
Upvotes: 1
Views: 360
Reputation: 4198
Consider adding a Grid
over all the rectangles, that way you would get MouseButtonUp
(as long as the mouse was released on the grid), but you would have to calculate which rectangle was moved over based on the MouseEventArgs.GetPosition
.
You might also want to look into UIElement.CaptureMouse()
, .ReleaseMouseCapture()
. Capturing mouse means that the MouseButtonUp
will be fired even when the mouse moves away from the MouseButtonDown
-Rectangle
, but the MouseMove
and MouseButtonUp
will be raised for the Capturing Rectangle (so you would still have to calculate the rectangles to highlight), until it calls ReleaseMouseCapture()
.
Upvotes: 2