WPF单击网格事件(z索引= 0),它位于另一个网格后面(zIndex = 1)

时间:2014-06-26 11:26:05

标签: c# wpf grid mouseevent z-index

我尝试创建一些网格。在每个Grid上我都有一个mouse-eventlistener,当我用鼠标悬停在这个Grid上时会激活一个事件。现在我用zIndex = 1和Rowspan = 3创建一个大网格。这个网格位于前面(因为zIndex = 1)。现在我有问题用zIndex = 1来触发大网格背后的网格事件。如何触发位于大网格后面的网格事件?

简单代码示例:

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

1 个答案:

答案 0 :(得分:1)

使用ZIndex 1将网格的IsHitTestVisible设置为false。

更多信息:IsHitTestVisible