WPF window shadow effect

51,097

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>
Share:
51,097

Related videos on Youtube

Victor
Author by

Victor

Thrilled to learn new things. Love programming, coffee and mountain bikes.

Updated on April 01, 2021

Comments

  • Victor
    Victor about 3 years

    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?

  • Андрей Москвичёв
    Андрей Москвичёв about 11 years
    Thank you very much! Very useful example.
  • Mohammed A. Fadil
    Mohammed A. Fadil about 9 years
    @HighCore, Thank you, it was very helpful and saved my time :)
  • OfficeAddinDev
    OfficeAddinDev over 6 years
    I've been using DropShadowEffect on a Window for some time. Perhaps this answer is now outdated.
  • Christopher Painter
    Christopher Painter about 4 years
    This seemed to give all the controls a shadow effect when I only wanted the window to have the effect. This blog article helped me. yuezhizizhang.github.io/wpf/2017/09/27/…