Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF DropShadowEffect appears on preview but not at runtime

So I implemented the following code within my grid:

        <Grid.Effect>
        <DropShadowEffect ShadowDepth="0"
                      Color="Black"
                      Opacity="1"
                      BlurRadius="30" RenderingBias="Quality"/>
       </Grid.Effect>

I can see the shadow appear in the preview; however, when I run it, there is no shadow. So I was wondering if I missed something.

xaml:

<Window x:Class="test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" Background="Transparent" WindowStyle="None" AllowsTransparency="True">
<Grid>
    <Grid.Effect>
        <DropShadowEffect ShadowDepth="0"
                  Color="Black"
                  Opacity="1"
                  BlurRadius="30" RenderingBias="Quality"/>
    </Grid.Effect>

    <Rectangle Height="350" Width="525" Fill="White" Grid.ColumnSpan="2">
    </Rectangle>
</Grid>

You should see a window with a shadow around the border. Then run it and its gone.

EDIT: So all I did was add a margin to the rectangle and the drop shadow appears. I'm assuming the window blocks the drop shadow.

like image 236
user3113237 Avatar asked Dec 17 '13 23:12

user3113237


1 Answers

Add a margin to your rectangle like this

<Rectangle Margin="10"  Height="350" Width="525" Fill="White" Grid.ColumnSpan="2">

The reason it needs the margin is because the drop shadow effect draws a larger outline than what is in the bounds of the rectangle. If you don't want to use the rectangle and just apply to it your grid then add the margin to your grid instead. Hope this helps.

like image 200
Josh Valdivieso Avatar answered Sep 29 '22 19:09

Josh Valdivieso