Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a control "transparent" to click events

I have a ListBox displaying some items, and in certain modes I "stamp" a kind of watermark across the top of it. I've done this with a Border containing a TextBlock with an Opacity of 0.5. All this works nicely.

However, I still want the user to be able to click on the items in the ListBox but if I click on the "stamp" it obviously eats the click events and they're not seen by the ListBox.

What do I have to do to prevent this? (i.e. allow the ListBox to see the Click event)

Thanks,

Craig

like image 578
Craig Shearer Avatar asked Dec 16 '08 22:12

Craig Shearer


1 Answers

You can do this with the IsHitTestVisible property:

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ListBox>
        <ListBoxItem>a</ListBoxItem>
        <ListBoxItem>b</ListBoxItem>
        <ListBoxItem>c</ListBoxItem>
    </ListBox>
    <Border Opacity="0.2" Background="Cyan" BorderBrush="Black" BorderThickness="5" IsHitTestVisible="False" >
        <TextBlock Text="EXAMPLE" FontSize="20" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    </Border>
</Grid>
like image 65
Robert Macnee Avatar answered Nov 07 '22 19:11

Robert Macnee