Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF window shadow effect

I am new to WPF technology. I have the following window declaration in WPF:

<Window x:Class="CustomWindows.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="480" Width="640" ScrollViewer.VerticalScrollBarVisibility="Disabled" WindowStyle="None" AllowsTransparency="True">
    <Window.Effect>
        <DropShadowEffect BlurRadius="15" Direction="-90" RenderingBias="Quality" ShadowDepth="2"/>
    </Window.Effect>
    <Grid>

    </Grid>
</Window>

But when I run it, the shadow does not appear. What can I do, or where is the misstake?

like image 412
Victor Avatar asked Nov 13 '12 19:11

Victor


People also ask

How to set shadow in WPF?

You can create a hard shadow by setting the BlurRadius property to 0.0 , which indicates that no blurring is used. You can control the direction of the shadow by modifying the Direction property. Set the directional value of this property to a degree between 0 and 360 .


1 Answers

DropShadowEffect cannot be applied to a Window. Instead, if you want to override the default window appearance, you have to apply the effect to some other element contained in the window:

<Window x:Class="WpfApplication2.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" WindowStyle="None"
        AllowsTransparency="True" Background="Transparent">

    <Grid Margin="20" Background="Red">
        <Grid.Effect>
            <DropShadowEffect BlurRadius="15" Direction="-90"
                              RenderingBias="Quality" ShadowDepth="2"/>
        </Grid.Effect>
        ...
      
    </Grid>
</Window>
like image 54
Federico Berasategui Avatar answered Oct 16 '22 13:10

Federico Berasategui