WPF:画布鼠标事件不会在空白区域触发 [英] WPF: Canvas mouse events not firing on empty space

查看:25
本文介绍了WPF:画布鼠标事件不会在空白区域触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Canvas 上设置了鼠标事件,如下所示:

I have set mouse events on a Canvas as follows:

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

但这些仅在 ImageRectangle 等子元素上有效,而不在空白处有效.我该如何解决这个问题?

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

推荐答案

没有设置背景颜色(显式或通过样式等)的控件将默认具有 null 背景颜色 - 使其不可命中测试.

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.

如果您将背景设置为透明"(或除 null ({x:Null}) 以外的任何内容),那么它将能够拾取鼠标事件

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

这篇关于WPF:画布鼠标事件不会在空白区域触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆