WPF DropShadowEffect appears at preview, but not at runtime

So, I implemented the following code in my grid:

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

I see a 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 it is gone.

EDIT: So, all I have done is add a margin to the rectangle and a shadow will appear. I assume the window is blocking the shadow.

+7
visual-studio wpf
source share
1 answer

Add margin to a rectangle like this

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

The reason it is needed is because the drop effect draws a larger outline than the one that is within the rectangle. If you don’t want to use a rectangle and just apply your grid to it, then add margin to your grid instead. Hope this helps.

+5
source share

All Articles