【问题标题】:OuterGlow effect in WPF not working with layered window?WPF 中的 OuterGlow 效果不适用于分层窗口?
【发布时间】:2011-01-22 00:34:00
【问题描述】:

谁能告诉我为什么 /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 框架? BitmapEffects 自 .NET 4.0 起已弃用
  • BitmapEffects 在 .net 4 中不起作用?那么我将如何在 .net 4 中做到这一点?

标签: c# wpf effects


【解决方案1】:

.NET 4.0 不再支持位图效果。

来自MSDN

重要在 .NET Framework 4 或 后来,BitmapEffect 类是 过时的。如果您尝试使用 BitmapEffect 类,你会得到一个 过时的异常。过时的 BitmapEffect 类的替代品 是效果类。多数情况 情况下,效果类是 明显更快。

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

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

【讨论】:

  • 我可以看看你要发布什么吗?
  • @Tommy:当然,我没有保存它,但我可以重新创建它
  • 有什么办法可以让矩形透明而不降低效果的可见度?
  • @Tommy:你可以为Rectangle更改Fill的alpha值,比如&lt;Rectangle Fill="#66B75050"&gt;
  • 我确实尝试过 - 由于某种原因它似乎也影响了 .Effect 属性 - 将进行更多测试。
猜你喜欢
  • 2010-12-16
  • 2012-11-02
  • 2011-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多