谁能告诉我为什么/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/