WPF 如何阻止 DropShadowEffect 传播到 child?

WPF how to stop DropShadowEffect to propagate to child?

我有一个无边界 Window,其中 Border 作为根节点,Canvas 作为 child。 canvas 用于通过 MouseMove 绘制折线。 边框有一个 DropShadowEffect,这会导致绘制 Canvas 时的性能显着下降。 我已经看到其他人 post 建议将边框和 Canvas 放在两个单独的网格中,但这对我的情况不起作用,因为如果我将边框放在网格中,我会失去阴影效果围绕 Window.

还有其他方法可以防止 Effect 传播吗?

这是 xaml 代码:

<Window x:Class="Test.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:Test"
    mc:Ignorable="d"
    Title="Test"
    Height="600" Width="1000"
    Background="{x:Null}"
    BorderThickness="0"
    BorderBrush="Black" 
    AllowsTransparency="True"
    WindowStyle="None">

<WindowChrome.WindowChrome>
    <WindowChrome
    CaptionHeight="0"
    ResizeBorderThickness="5,5,20,20"/>
</WindowChrome.WindowChrome>

<Border x:Name="borderShadow" Margin="0,0,15,15" BorderThickness="2,1" BorderBrush="Black" Background="#FF355870">
    <Border.Effect>
        <DropShadowEffect Color="Black"
                      Direction="315"
                      BlurRadius="15"
                      ShadowDepth="10"/>
    </Border.Effect>

    <Grid Background="#FF355870">
        <Canvas x:Name="canvasBoard" Background="#00000000" MouseMove="canvasBoard_MouseMove" MouseDown="canvasBoard_MouseDown" MouseUp="canvasBoard_MouseUp"/>
    </Grid>
</Border>
</Window>

您可以这样将边框单独放在网格中:

<Grid>
<Border x:Name="borderShadow" Margin="0,0,15,15" BorderThickness="2,1" BorderBrush="Black" Background="#FF355870">
    <Border.Effect>
        <DropShadowEffect Color="Black"
                      Direction="315"
                      BlurRadius="15"
                      ShadowDepth="10"/>
    </Border.Effect>
</Border>
<Grid Background="#FF355870">
    <Canvas x:Name="canvasBoard" Background="#00000000" MouseMove="canvasBoard_MouseMove" MouseDown="canvasBoard_MouseDown" MouseUp="canvasBoard_MouseUp"/>
</Grid>
</Grid>