WPF窗口阴影效果

Vic*_*tor 18 c# wpf effects shadow

我是WPF技术的新手.我在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>
Run Code Online (Sandbox Code Playgroud)

但是当我运行它时,阴影不会出现.我能做什么,或者在哪里发生错误?

Fed*_*gui 42

DropShadowEffect不能适用于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>
Run Code Online (Sandbox Code Playgroud)

  • 我已经在窗口上使用 DropShadowEffect 有一段时间了。也许这个答案现在已经过时了。 (2认同)
  • 当我只希望窗口具有阴影效果时,这似乎为所有控件提供了阴影效果。这篇博客文章对我有帮助。http://yuezhizizhang.github.io/wpf/2017/09/27/drop-shadow-on-chromeless-wpf-window.html (2认同)