在WPF中单击鼠标时如何使用较低的zindex进行控制? [英] How to get control with lower zindex when mouse clicked in wpf?

查看:149
本文介绍了在WPF中单击鼠标时如何使用较低的zindex进行控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一画布上有多个控件,并且一个控件可能被另一个控件覆盖.它们都具有相同的zIndex,但是对于加载的顺序,有些是上升的,而另一些是下降的. 我的问题是Acontrol是否超过Bcontrol,我单击它们,但只有A会获得click事件.我也如何让B参加活动?谢谢.

I've several controls in the same canvas and may one be covered by another. They are all with same zIndex, but for the order loaded, some being up and others down. My Question if Acontrol is over Bcontrol, and I click on them, but only A gets the click event. How can I make B get the event, too? Thanks.

推荐答案

如果您只希望后面的控件可以获取事件,那么对于第一个控件前面的所有控件,都必须设置IsHitTestVisible = False后面的人来获得活动-但这不是您想要的.

If you only wanted the one in the back to get the event, then for all the controls in front of the first one, you have to set IsHitTestVisible = False for the one behind to get the event - but this isn't what you want.

如果您希望所有人都得到事件,则可以将整个UI视为元素树.您正在谈论的所有这些控件都是同级控件.单击某项时,第一个得到通知的是父级,并且如果不处理该单击,则会将该父级传递到该父级在该鼠标位置处的可见子元素,依此类推,直到得到处理.阻止被点击的孩子处理鼠标单击的唯一方法是让所有兄弟姐妹的共同父母首先处理该事件.

If you want them all to get the event think of the entire UI as a tree of elements. All of these controls you're talking about are siblings. When something is clicked, the parent is the first to get notified, and if it doesn't handle the click, it gets passed down to the visible child element of that parent at that mouse position, and so on until it's handled. Your only way to stop the child that gets clicked from handling the mouse click is to have the common parent of all the siblings handle the event first.

然后,您将不得不在父级的处理程序中执行一些巧妙的操作,以调用可以在鼠标下方找到的所有子元素的click事件-问题是,该框架用于完成确定哪个控件被执行的艰苦工作.在鼠标下,您现在将必须进行艰苦的工作.

You will then have to do something clever in the parent's handler to invoke the click event of all child elements that can be found beneath the mouse - the problem is that whereas the framework used to do the hard work of determining which control was under the mouse, you will will now have to do that hard work.

这篇关于在WPF中单击鼠标时如何使用较低的zindex进行控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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