I know there is a mouse click event for every control but is there a way to determine when the mouse click is not on the control?
Asked
Active
Viewed 5,874 times
1
-
1. No, there's not a mouse click event for every control. Only things that are logically clickable -- e.g. buttons, checkboxes, menu items, hyperlinks -- have Click events. Other controls, like TextBoxes and Images, do not. If you want something else to be clickable -- e.g. an image -- then you should re-style a button. 2. If the click isn't on control X, then control X won't get notified -- the control Y (the one you actually *did* click) gets the event. – Joe White Jun 20 '09 at 23:05
4 Answers
0
you can check the IsMouseOver for false, and if you want to hook an action when the IsMouseOver == false, you can override the metadata of that dp.

abdelkarim
- 586
- 6
- 11
0
This won't work for the Click
event (because there is no tunneling version, only a bubbling version), but you could handle the routed PreviewMouseLeftButtonDown
on the Window
class and check to see if the target control is in the hit tree.

Josh G
- 14,068
- 7
- 62
- 74
0
You can call CaptureMouse and then that object will receive all mouse events. You can then determine from the point of the mouse down whether it was within the bounds of your control or not. Or you can listen for the LostMouseCapture event instead.

Alex B
- 2,766
- 1
- 17
- 8