简体   繁体   中英

WPF Clickevent for Grid (zIndex=0) which is behind another Grid (zIndex =1)

I try to create some Grids. On every Grid I have a mouse-eventlistener, which fire a event when I go with my mouse over this Grid. Now I create a big Grid with zIndex = 1 and Rowspan = 3. This Grid is located in front (because of zIndex = 1). Now I have problems to fire the events of Grids which lay behind the big Grid with zIndex = 1. How can I fire the events of the Grid which are located behind the big Grid?

Simple Code Example:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="1*"/>
        <RowDefinition Height="1*"/>
        <RowDefinition Height="1*"/>
        <RowDefinition Height="1*"/>
        <RowDefinition Height="1*"/>
        <RowDefinition Height="1*"/>
    </Grid.RowDefinitions>

    <Grid Grid.Row="0" Background="AliceBlue"/>
    <Grid Grid.Row="1" Grid.RowSpan="3" Panel.ZIndex="1" Background="Aqua" Opacity="0.2" PreviewMouseMove="Grid_PreviewMouseMove_1"/>
    <Grid Grid.Row="2" PreviewMouseMove="Grid_PreviewMouseMove" Background="AntiqueWhite"/>
    <Grid Grid.Row="3" PreviewMouseMove="Grid_PreviewMouseMove" Background="Beige"/>
    <Grid Grid.Row="4" PreviewMouseMove="Grid_PreviewMouseMove" Background="Bisque"/>
    <Grid Grid.Row="5" PreviewMouseMove="Grid_PreviewMouseMove" Background="BlanchedAlmond"/>

</Grid>

Set the IsHitTestVisible to false for the Grid with ZIndex 1.

For More Info : IsHitTestVisible

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM