如何让 ScrollViewer 将 Click 事件传递到其背后的控件?
我有两个相互重叠的网格,顶层位于 ScrollViewer 中。问题是底层有点击事件,并且它们不会被那里的 ScrollViewer 触发。
有没有办法让ScrollViewer将点击事件传递给它后面的控件?
<Grid>
<local:MyBackgroundControlWithClickEvents />
<ScrollViewer>
<local:MyForegroundControlWithClickEvents />
</ScrollViewer>
</Grid>
I have two grids overlaying one another, and the top layer is in a ScrollViewer. The problem is the bottom layer has click events, and they don't get triggered with the ScrollViewer there.
Is there a way to have the ScrollViewer pass click events to the control behind it?
<Grid>
<local:MyBackgroundControlWithClickEvents />
<ScrollViewer>
<local:MyForegroundControlWithClickEvents />
</ScrollViewer>
</Grid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
单击事件将可视化树向上冒泡到根,因为您的控件是不是
ScrollViewer
的父级,它不会接收这些事件。我知道它们可能在屏幕上重叠,但就视觉树而言,它们是兄弟姐妹,而不是父/子。要实现此目的,您可以将
MyBackgroundControlWithClickEvents
更改为ContentControl
并在其中托管ScrollViewer
。Click events bubble up the visual tree to the root, because your control is not a parent of the
ScrollViewer
, it will not receive these events. I know they might overlap on screen, but as far as the visual tree is concerned they are siblings, not parent / child.To make this work, you could change
MyBackgroundControlWithClickEvents
into aContentControl
and host theScrollViewer
within it.