Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you set IsHitTestVisible to True on a child of something where it's set to false?

I have a message which is within a border and is displayed in front of a MDI client area. Because it's just a message, I set it's IsHitTestVisible to false. For convenience, I've also included a button within it so the user can simply click the button to start a new diagram.

However, because the border has its IsHitTestVisible set to False, it shorts out the True value of the button so the user can't click on the button.

That said, how can you make a control invisible to the mouse, while still allowing one of its children to receive mouse events?

Here's a screenshot:

enter image description here

We want the blue area with text to be hit-test invisible, but we want the button to still be able to be pressed. Thoughts? (And yes, I already know about stacking the two items in a grid, but that messes with the layout.

like image 279
Mark A. Donohoe Avatar asked Aug 27 '12 19:08

Mark A. Donohoe


1 Answers

DISCLAIMER: It looks it wont solve exact problem that OP has but i will keep it here because it might be helpful for others with similar issue.

Clicking on grid should not register any mouse events on grid.

<Grid Background="{x:Null}">
   <Button/>
<Grid/>

EDIT: When you want background to be visibile then i would suggest this: For demostration i set cursor="hand" on border

<Canvas>
    <Border Height="300" Width="300" Background="Red" Cursor="Hand" IsHitTestVisible="False"/>
    <Button Content="click"/>
</Canvas>

or

<Grid>
    <Border  Background="Red" Cursor="Hand" IsHitTestVisible="False" />
    <Button Content="click" HorizontalAlignment="Center"/>
</Grid>

It both cases the trick is that the control (button) is not child of parent with IsHitTestVisible="False" and it is just overlaping the background control

like image 87
JanH Avatar answered Oct 10 '22 00:10

JanH