1

无论如何使用 IsHitTestVisible 为面板(thirdGrid)内的控件触发 MouseEvents 为假。我已经在面板内加载了 IsHitTestVisible 为 false 的按钮。但我希望 Button 触发其鼠标事件。我可以使用任何解决方法来实现这一目标吗?如果我将 thirdGrid 的 IsHitTestVisible 设置为 true,则不会为我的 firstGrid 触发鼠标事件。

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

4

1 回答 1

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>
于 2013-08-26T22:21:03.883 回答