1

我创建了一个没有样式的窗口并添加了自定义边框。我需要我的窗户投下阴影。

<Border BorderBrush="#000000 "           
                    BorderThickness="1,0,1,1" Width="400" 
                            Height="400" 
                            VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                    CornerRadius="10, 10, 0, 0"
                    Background="Black">
                        <Border.Effect>
                            <DropShadowEffect Color="Black" Direction="320" 
                                    ShadowDepth="5" Opacity="1" BlurRadius="5" />
                        </Border.Effect></Border>

但是当我像这样设置宽度和高度时,我的阴影消失了:

Width="{Binding RelativeSource={RelativeSource FindAncestor, 
                    AncestorType={x:Type Window}}, Path=Width}" 

请帮我找到解决方案。谢谢

4

3 回答 3

1

由于我们没有您解决方案的全部范围,我必须假设边框位于分配给窗口样式的 ControlTemplate 内。请记住,如果您要将 DropShadowEffect 应用于根窗口,则需要对其进行填充,否则您将看不到它。将 Padding="10" 应用于 Border,您应该会看到它。

于 2012-05-11T14:14:00.730 回答
0

尝试将阴影的 X 和 Y 厚度添加到您的 Windows 尺寸

于 2012-05-11T13:54:47.567 回答
0

不要在根视觉效果上应用效果!在这种情况下,它们适用于视觉树下的所有子级,并且会导致性能下降。使用下一个模式:

<Grid x:Name="RootWindowGrid">
   <Border x:Name="BorderWithEffect" Margin="5">
      <Border.Effect>
         <DropShadowEffect Color="Black" Direction="320" ShadowDepth="5" Opacity="1" BlurRadius="5" />
       </Border.Effect>
   </Border>

   <Border x:Name="RootBorder_ForAll_Another_Window_Visuals" Margin="5"/>
</Grid>

余量取决于效果强度。

于 2012-05-11T14:52:50.353 回答