使用 BorderThickness = 0 向 WPF 窗体添加阴影

Adding shadow to WPF form with BorderThickness = 0

我有一个 WPF 无边框 window,阴影设置为如下所示的网格:

<Window x:Class="Wpf.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" BorderThickness="0">
    <Grid>
        <Grid.Effect>
            <DropShadowEffect BlurRadius="15" Direction="-90" RenderingBias="Quality" ShadowDepth="2"/>
        </Grid.Effect>
    </Grid>
</Window>

但是,当BorderThickness 设置为0 时,阴影不会出现。当我增加它时,阴影会出现,但是当使用 DragMove() 将 window 移动到屏幕边缘时,会留下一个间隙(大概是 BorderThickness 的宽度)。

因此,如何在 BorderThickness 设置为 0 的情况下在 window 周围添加阴影?提前致谢。

 <Window x:Class="WpfApp7.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfApp7"
    mc:Ignorable="d" WindowStyle="None" 
    AllowsTransparency="True" Background="Transparent" BorderThickness="0"
    Title="MainWindow" Height="450" Width="800">
<Grid Margin="10">
    <Grid.Background>
        <SolidColorBrush Color="Green" Opacity="1"/>
    </Grid.Background>
      <Grid.Effect>
        <DropShadowEffect Color="Black"  BlurRadius="15" Direction="-90" 
                  RenderingBias="Quality" ShadowDepth="2"/>
      </Grid.Effect>
    </Grid>

:) 只需向网格添加边距。显示阴影需要space。