Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF如何阻止DropShadowEffect传播到子级?_C#_Wpf_Dropshadoweffect - Fatal编程技术网

C# WPF如何阻止DropShadowEffect传播到子级?

C# WPF如何阻止DropShadowEffect传播到子级?,c#,wpf,dropshadoweffect,C#,Wpf,Dropshadoweffect,我有一个无边界窗口,其中边界作为根节点,画布作为子节点。 画布用于通过鼠标移动绘制多段线。 边框具有DropShadow效果,这会导致在画布上绘制时性能显著下降。 我已经看到一些其他帖子建议将边框和画布放在两个单独的网格中,但这对我的情况不起作用,因为如果我将边框放在网格中,我会丢失窗口周围的阴影效果 还有另一种方法可以防止效果的传播吗 这是xaml代码: <Window x:Class="Test.MainWindow" xmlns="http://schemas.microso

我有一个无边界窗口,其中边界作为根节点,画布作为子节点。 画布用于通过鼠标移动绘制多段线。 边框具有DropShadow效果,这会导致在画布上绘制时性能显著下降。 我已经看到一些其他帖子建议将边框和画布放在两个单独的网格中,但这对我的情况不起作用,因为如果我将边框放在网格中,我会丢失窗口周围的阴影效果

还有另一种方法可以防止效果的传播吗

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


该效果将应用于其应用于的控件内的任何内容。栅格将剪裁效果。画布需要在您应用该效果的任何对象之外。它不会夹。窗口是一个contentcontrol,因此它只能有一个根控件。你最好把它做成画布。将边框放入其中,并将其设置为HITTESVISIBLE false,以便所有事件都能正常进行。@Andy感谢您的回答!不幸的是,我无法按照您的建议执行操作,因为实际应用程序将有其他网格和控件,带有边距和填充,画布将位于其他网格中的一个网格中,因此如果我将具有效果的边框放置在画布中,它将不会将阴影应用于窗口,而是应用于包含画布的网格。无法告诉画布不要使用父控件的效果?无法避免将该效果应用于子控件。