无论如何,使用IsHitTestVisible false为面板内的控件触发MouseEvents

时间:2013-08-26 14:28:42

标签: silverlight

无论如何都要使用IsHitTestVisible false为面板(thirdGrid)内的控件触发MouseEvents。我已将面板中的按钮加载到IsHitTestVisible为false。但是我希望Button能够激活它的鼠标事件。我可以使用任何解决方法来实现这一目标吗?如果我将thirdGrid的IsHitTestVisible设置为true,则不会为我的firstGrid触发Mouse事件。

    

<Grid Background="AliceBlue" x:Name="firstGrid" MouseLeftButtonUp="Grid_MouseLeftButtonUp"/>

<Grid Background="AliceBlue" x:Name="secondGrid" IsHitTestVisible="False"/>

<!--Event won't fire for this control since i'm setting IsHitTestVisible to false-->
<Grid x:Name="thirdGrid" IsHitTestVisible="False">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <!--Is there anyway to make this button to fire its events, even if i set its panles IsHitTestVisible to false-->
    <Button Content="click"  Width="150" Height="30" 
        MouseLeftButtonDown="Button_MouseLeftButtonDown"
            IsHitTestVisible="True" />
</Grid>        

1 个答案:

答案 0 :(得分:0)

从网格中取出按钮测试为假的按钮。然后使用边距定位它。如果您尝试以下操作,它会将其置于屏幕中心,并且两个事件都将触发。

<Grid>
<Grid Background="AliceBlue"
      x:Name="firstGrid"
      MouseLeftButtonUp="Grid_MouseLeftButtonUp" />
<Grid Background="AliceBlue"
      x:Name="secondGrid"
      IsHitTestVisible="False" />
<!--Event won't fire for this control since i'm setting IsHitTestVisible to false-->
<Grid x:Name="thirdGrid"
      IsHitTestVisible="False">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <!--Is there anyway to make this button to fire its events, even if i set its panles IsHitTestVisible to false-->

</Grid>
     <Button Content="click"
            Width="150"
            Height="30"
            Click="ButtonBase_OnClick"
             />
</Grid>