开发者

WPF: Canvas mouse events not firing on empty space

开发者 https://www.devze.com 2022-12-24 17:02 出处:网络
I have set mouse events on a Canvas as follows: <Canvas MouseUp=\"CanvasUp\" MouseDown=开发者_运维技巧\"CanvasDown\" MouseMove=\"CanvasMove\">

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?


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


Set the background color. It defaults to null.

Use Background="White" for instance.

0

精彩评论

暂无评论...
验证码 换一张
取 消