透明背景上的鼠标事件 [英] Mouse event on transparent background

查看:26
本文介绍了透明背景上的鼠标事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了几个具有透明背景的画布,并希望在其上进行一些移动事件.

I have create several canvas with transparent background and wanna make some move event on it.

但是,我发现所有鼠标事件(例如 MouseLeftButtonDown)都不能作用于画布的背景为 Null 或透明.但是如果我将背景设置为某种纯色(比如红色或蓝色),鼠标事件就会正常工作.

However, I found that all mouse event (e.g. MouseLeftButtonDown) cannot function of the background of the canvas is Null or Transparent. But if I set the background to some solid color (say, red or blue), the mouse event function well.

为什么?

我可以让鼠标事件在透明背景下正常工作吗?

Could I make the mouse event function properly with transparent background?

谢谢!

推荐答案

我不知道为什么你会得到你得到的结果,但是当背景透明时它应该可以正常工作(即你明确地将它设置为 Brushes.Transparent,通过 XAML 或代码).如果它为 null,WPF 将不会将它包含在命中测试中,因此它不符合鼠标事件的条件.

I'm not sure why you get the results you get but it should work fine when the background is transparent (i.e. you explicitly set it to Brushes.Transparent, either through XAML or code). If it is null, WPF will not include it in hit testing, and thus it won't be eligible for mouse events.

参见例如http://msdn.microsoft.com/en-us/library/ms752097.aspx(透明的视觉对象也可以被命中测试.)

您的元素树中很可能还有另一个 UIElement 正在捕获并处理 在你的画布看到它之前的鼠标事件(即通过将 e.Handled 设置为 true)

Most likely you have another UIElement in your element tree that is capturing and handling the mouse event before your canvas sees it (i.e. by setting e.Handled to true)

这篇关于透明背景上的鼠标事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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