C# WPF 窗口阴影效果

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13367249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 08:19:54  来源:igfitidea点击:

WPF window shadow effect

c#wpfeffectsshadow

提问by Victor

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

我是 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>

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

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

采纳答案by Federico Berasategui

DropShadowEffectcannot 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:

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>