0

I use the IsMouseOver property frequently in my WPF program. Unfortunately, I have other visual elements from other branches of the visual tree that sometimes cover up my controls. When they cover up my controls, the IsMouseOver becomes false on my controls, even when my mouse is over the covered up control.

How can my control have a property like IsMouseOver that doesn't care if it's covered up at the cursor location? Like a hit test that can tunnel threw covers.

I looked at this solution but I don't think I can use it, because it basically uses polling every time that the mouse moves. I think that would slow down my program significantly, because my visual tree is extensive.

Note that the visual elements that cover up my controls are not children of my controls.

Edit: Setting IsHitTestVisible to false on the element that is doing the covering would be a very nice solution, but when I do that then the covering element doesn't interact with the mouse at all. I need both the covered and the covering elements to react to the mouse.

4

1 回答 1

0

通过设置使覆盖控件对命中测试不可见IsHitTestVisible="False"

<Grid>
  <Control1/>

  <!-- Control2 will visually "cover" Control1, but mouse events will "pass thru" To Control1 -->
  <Control2 IsHitTestVisible="False"/>
</Grid>
于 2013-08-09T00:25:29.020 回答