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

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

问题描述

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

I have set mouse events on a Canvas as follows:

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

但是这些仅在诸如 Image Rectangle ,而不是在空白处。
我该如何解决?

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.

如果将背景设置为透明(或除null(<$ c之外的任何其他值),则默认为背景色-使其不可命中测试。 $ c> {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天全站免登陆