WPF DropShadowEffect出现在预览上,但在运行时不显示 [英] WPF DropShadowEffect appears on preview but not at runtime

查看:195
本文介绍了WPF DropShadowEffect出现在预览上,但在运行时不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在网格中实现了以下代码:

So I implemented the following code within my grid:

        <Grid.Effect>
        <DropShadowEffect ShadowDepth="0"
                      Color="Black"
                      Opacity="1"
                      BlurRadius="30" RenderingBias="Quality"/>
       </Grid.Effect>

我可以看到阴影出现在预览中;但是,当我运行它时,没有阴影.所以我想知道我是否错过了什么.

I can see the shadow appear in the preview; however, when I run it, there is no shadow. So I was wondering if I missed something.

xaml:

<Window x:Class="test.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" Background="Transparent" WindowStyle="None" AllowsTransparency="True">
<Grid>
    <Grid.Effect>
        <DropShadowEffect ShadowDepth="0"
                  Color="Black"
                  Opacity="1"
                  BlurRadius="30" RenderingBias="Quality"/>
    </Grid.Effect>

    <Rectangle Height="350" Width="525" Fill="White" Grid.ColumnSpan="2">
    </Rectangle>
</Grid>

您应该看到一个边框周围有阴影的窗口.然后运行它,它消失了.

You should see a window with a shadow around the border. Then run it and its gone.

编辑:因此,我所做的就是向矩形添加边距,并出现阴影.我假设窗口挡住了阴影.

So all I did was add a margin to the rectangle and the drop shadow appears. I'm assuming the window blocks the drop shadow.

推荐答案

像这样在您的矩形中添加边距

Add a margin to your rectangle like this

<Rectangle Margin="10"  Height="350" Width="525" Fill="White" Grid.ColumnSpan="2">

之所以需要页边距,是因为阴影效果所绘制的轮廓比矩形范围内的轮廓要大.如果您不想使用该矩形,而只是将其应用于网格,则可以将边距添加到网格中.希望这会有所帮助.

The reason it needs the margin is because the drop shadow effect draws a larger outline than what is in the bounds of the rectangle. If you don't want to use the rectangle and just apply to it your grid then add the margin to your grid instead. Hope this helps.

这篇关于WPF DropShadowEffect出现在预览上,但在运行时不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆