c# - WPF 中的 OuterGlow 效果不适用于分层窗口?

标签 c# wpf effects

谁能告诉我为什么/no/outerglow 效果在我的 WPF 窗口上起作用?这是代码示例:

<Window x:Class="SocialShock_WPF_Client.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"
        AllowsTransparency="True" 
        WindowStyle='None' 
        Background="Transparent" 
        Loaded="Window_Loaded">
    <Grid>
        <Rectangle Margin="12" Name="rectangle1" Fill="#FFB75050">
            <Rectangle.BitmapEffect>
                <OuterGlowBitmapEffect GlowColor="Black" GlowSize="20" />
            </Rectangle.BitmapEffect>
        </Rectangle>
    </Grid>
</Window>

和生成的图像:

http://img408.imageshack.us/img408/6213/1c1761f31ce6408d948e266.png

边缘周围没有发光。 不仅发光没有出现在矩形上,而且我添加到窗口的任何其他控件也不能接受发光。

编辑:它在 .Net 4.0 中

最佳答案

.NET 4.0 不再支持 BitmapEffects。

来自 MSDN

Important In the .NET Framework 4 or later, the BitmapEffect class is obsolete. If you try to use the BitmapEffect class, you will get an obsolete exception. The non-obsolete alternative to the BitmapEffect class is the Effect class. In most situations, the Effect class is significantly faster.

没有真正好的替代品,但您可以尝试使用 ShadowDepth 为 0 的 DropShadowEffect。示例

<Rectangle Margin="12" Name="rectangle1" Fill="#FFB75050">
    <Rectangle.Effect>
        <DropShadowEffect ShadowDepth="0"
                          Color="Black"
                          Opacity="1"
                          BlurRadius="12"/>
    </Rectangle.Effect>
</Rectangle>

如果我理解正确的话,

在后台添加效果

DropShadowEffect dropShadowEffect = new DropShadowEffect();
dropShadowEffect.ShadowDepth = 0;
dropShadowEffect.Color = Colors.Black;
dropShadowEffect.Opacity = 1;
dropShadowEffect.BlurRadius = 12;
rectangle1.Effect = dropShadowEffect;

在代码隐藏中修改效果

DropShadowEffect dropShadowEffect = rectangle1.Effect as DropShadowEffect;
dropShadowEffect.BlurRadius = 24;

关于c# - WPF 中的 OuterGlow 效果不适用于分层窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4765314/

相关文章:

c# - 绑定(bind)运行次数可变的 RichTextBox

r - 从 lme4 mer 模型对象中提取随机效应方差

C# 浮点表达式 : strange behavior when casting the result float to int

c# - Silverlight 中动态 WCF 客户端代理的解决方案?

c# - 如何将文本 block 绑定(bind)到 WPF 中的 DataGrid 列的总和?

.net - 设置其他文件的路径时,如何引用 WPF XAML 中的根项目目录?

Silverlight 滚动动画占用大量 CPU 时间

c# - 将渲染后效果应用于 XNA 中的 SpriteBatch

c# - EWS 托管 API : Can I load properties for multiple items with one EWS call, 仅给出项目 ID?

c# - 您是否授予用户访问您的数据库的权限,或者是否通过共享用户名执行查询