鼠标事件未到达 UIElement
我有一个由 System.Windows.Controls.Canvas
对象组成的 6x8 网格。左上角画布不接收鼠标事件,而其他画布则接收鼠标事件。我尝试了 OnMouseMove 和 OnMouseClick 事件。
子对象未处理该事件,因为 System.Windows.Media.VisualTreeHelper#GetChildrenCount()
不显示任何子对象。我也无法捕捉到 PreviewOnMouseMove
。我的画布前面是否可以有一些(可能是透明的)控件优先?
I have a 6x8 grid of System.Windows.Controls.Canvas
objects. The top left canvas does not receive mouse events while all the others do. I tried OnMouseMove
and OnMouseClick
events.
A child object isn't handling the event because System.Windows.Media.VisualTreeHelper#GetChildrenCount()
doesn't show any children. I couldn't catch PreviewOnMouseMove
either. Can there be some (perhaps transparent) control in front of my canvas that is taking precedence?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
终于找到解决办法了。每个
Canvas
都有Adorner
。根据 这篇 MSDN 文章,装饰器在底层 UI 元素之前接收鼠标事件做。我将所有装饰器的IsHitTestVisible
属性设置为false
。Finally found a solution. Each of the
Canvas
es haveAdorner
s. According to this MSDN article, adorners receive mouse events before the underlying UI element does. I set theIsHitTestVisible
property of all my adorners tofalse
.我希望这对您有帮助,只需将
Canvas
的Background
属性设置为Transparent
值即可:祝你好运!
I hope this helps you, Just set
Transparent
value to theBackground
property for theCanvas
:Good luck!