开发者

How can I make my ScrollViewer pass Click events through to the control behind it?

开发者 https://www.devze.com 2023-04-08 16:22 出处:网络
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 th

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>


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 a ContentControl and host the ScrollViewer within it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号