Search code examples
wpfxamlscrollviewermouseclick-event

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


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>

Solution

  • 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.