Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Canvas mouse events not firing on empty space

Tags:

canvas

wpf

xaml

I have set mouse events on a Canvas as follows:

<Canvas MouseUp="CanvasUp" MouseDown="CanvasDown" MouseMove="CanvasMove"> ... </Canvas> 

But these are active only on the child elements like Image and Rectangle, not on the empty space. How can I solve this?

like image 355
user279244 Avatar asked Mar 24 '10 11:03

user279244


2 Answers

A control with no background color set (explicitly or through styles etc) will default to having a background color of null - making it not hit-testable.

If you set the background to "Transparent" (or anything other than null ({x:Null})) then it will be able to pick up the mouse events

like image 179
Rob Fonseca-Ensor Avatar answered Oct 14 '22 00:10

Rob Fonseca-Ensor


Set the background color. It defaults to null.

Use Background="White" for instance.

like image 31
Mark Synowiec Avatar answered Oct 13 '22 23:10

Mark Synowiec