Search code examples
wpfstylesdropshadow

WPF DropShadow Effect disapear when setting background color of control


In this example, I have a TextBlock with a DropShadowEffect:

<TextBlock Foreground="Black" Text="All Tasks">
    <TextBlock.Effect>
        <DropShadowEffect ShadowDepth="1.2" 
                          Direction="270" 
                          Opacity="0.6" 
                          BlurRadius="1" 
                          Color="Red"/>
    </TextBlock.Effect>
</TextBlock>

This produces the following output:

output

If I set any Background color for the TextBlock, the shadow should disappear:

output

How can I set this property while keeping the drop shadow?


Solution

  • The DropShadowEffect doesn't disappear - it now applies to the whole rectangle.

    This gives the desired effect:

    <Border Background="Green">
        <TextBlock Foreground="Black" Text="All Tasks">
            <TextBlock.Effect>
                <DropShadowEffect ShadowDepth="1.2" 
                                  Direction="270" 
                                  Opacity="0.6" 
                                  BlurRadius="1" 
                                  Color="Red"/>
            </TextBlock.Effect>
        </TextBlock>
    </Border>