允许鼠标事件通过UserControl中的网格

时间:2017-09-18 17:17:31

标签: c# wpf

我已经看到这个link来解决我的问题,但它对我不起作用,因为我的布局中有两个网格,我需要其中一个获得鼠标事件而另一个没有。第一个网格就像一个带按钮的标题栏,我可以移动窗口。有没有人有任何解决方案或建议?

我的Xaml

 <UserControl ...>
    <Grid>
        <Grid.RowDefinitions>
           <RowDefinition Height="Auto"/>
           <RowDefinition Height="*"/>
       </Grid.RowDefinitions>

       <Grid Grid.Row="0">

             ....

        </Grid>

        <Grid Grid.Row="1" 
              behaviors:PopupBehavior.IsPopupEventTransparent="True">

              .....

        </Grid>
   </Grid></UserControl>

2 个答案:

答案 0 :(得分:1)

如果要忽略任何WPF UI元素上的鼠标输入,您可以将其IsHitTestVisible属性设置为false

示例:

<Grid>
  <Button Click="OnButtonClick" Content="The Button" />
  <Border Background="Red" Opacity="0.5" IsHitTestVisible="False" />
</Grid>

红色半透明边框将显示在按钮前面。仍然,该按钮将接收点击事件,因为边界禁用了命中测试。

进一步阅读:MSDN

答案 1 :(得分:1)

如果您在根元素上将IsHitTestVisible属性设置为false,则无法在其任何子元素上将其设置为true。正如你所看到的,这个问题永远得不到答案How can you set IsHitTestVisible to True on a child of something where it's set to false?

因此,您可以忘记使用HitTestVisible子进行传递UserControl。

相关问题