简体   繁体   中英

WPF how to stop DropShadowEffect to propagate to child?

I have a borderless Window with a Border as root node and Canvas as child. The canvas is used to draw Polyline by MouseMove. The border have a DropShadowEffect and this cause a significant drop of performance to draw on Canvas. I have already seen that some others post suggest to put the Border and Canvas in 2 separate Grid, but this will not work for my case since if I put the Border inside a Grid I lose the shadow effect around the Window.

There is another way to prevent the propagation of the Effect?

This is the xaml code:

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

You can put the Border alone inside a Grid in this way:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM