Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
741 views
in Technique[技术] by (71.8m points)

xaml - WPF: Canvas mouse events not firing on empty space

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...