在透明背景鼠标事件 [英] Mouse event on transparent background
问题描述
我创建几个帆布搭配透明背景,想做出一些举动的事件就可以了。
I have create several canvas with transparent background and wanna make some move event on it.
不过,我发现,所有的鼠标事件(例如的MouseLeftButtonDown)无法画布的背景功能为空或透明。但是,如果我将背景设置为一些纯色(比如,红色或蓝色),鼠标事件功能良好。
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?
感谢您!
推荐答案
我不知道为什么你得到你所得到的结果,但是当背景是透明的,应该工作正常(即你明确地将其设置为<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.media.brushes.transparent.aspx\">Brushes.Transparent,无论是通过XAML或code)。如果为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.
请参阅例如<一href=\"http://msdn.microsoft.com/en-us/library/ms752097.aspx\">http://msdn.microsoft.com/en-us/library/ms752097.aspx (视觉对象,它是透明的,也可点击测试。的)
最有可能你在被捕获的和处理鼠标的元素树的另一个的UIElement你的画布事件之前看到它(即通过e.Handled设置为真正
)
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屋!