I have an Image control in WPF which contains an image with lots of transparent pixels. Right now, the MouseDown event on Image fires whenever I click within the full rectangular region of the Image control. I would like some way to detect if the mouse click occurred on a nontransparent portion of the image.
What would be the best way of doing this?
Using the technique in this answer you can derive from
Imageto create anOpaqueClickableImagethat only responds to hit-testing in sufficiently non-transparent areas of the image:after adding this class, just use it like a regular image: