开发者

OuterGlow effect in WPF not working with layered window?

can any one tell me why /no/ outerglow effects are working on my WPF Window? here is an example of the code:

<Window x:Class="SocialShock_WPF_Client.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.mic开发者_JAVA技巧rosoft.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>

and the resulting image:

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

No glow around the edge. not only is the glow not appearing on the rectangle, but any other controls i add to the window cannot accept glows either.

EDIT: its in .Net 4.0


BitmapEffects are no longer supported in .NET 4.0.

From 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.

There isn't a really good substitute but you can try to use a DropShadowEffect with a ShadowDepth of 0. Example

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

If I understood you comment correctly,

Adding the effect in code behind

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

Modifying the effect in code behind

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜