Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In XAML, Why a Transparent background blocks this Trigger?

Tags:

wpf

xaml

This happens only when I set the background to Transparent, which is the effect that I need. Changing the background to AliceBlue for example, allows the trigger to take an effect. What could be missing here behind the scenes?

<Window
    AllowsTransparency="True"
    Background="Transparent">
<Window.Style>
    <Style>
        <Style.Triggers>
            <Trigger Property="Window.IsActive" Value="True">
                <Setter Property="Window.Cursor" Value="ArrowCD" />
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Style>
<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
    <TextBlock>
        Some Text    
    </TextBlock>
</Grid>
</Window>
like image 276
usefulBee Avatar asked Dec 10 '13 20:12

usefulBee


1 Answers

This is a side effect of how layered windows are handled at the Win32 level: wholly transparent pixels (i.e., with zero alpha) are not visible to hit testing, and therefore will not generate mouse events.

Since all mouse events pass through your window, your window's cursor will not be displayed. So, while your trigger may fire, it is rendered useless by the hit testing behavior. Even if you hard-code the window's Cursor property to ArrowCD, you will never see that cursor unless the mouse is over non-transparent content within the window.

like image 108
Mike Strobel Avatar answered Nov 01 '22 09:11

Mike Strobel