views:

272

answers:

6

I am having a problem using VS2010 and framework version 4 with bitmap effects. If I have the code below and run it in a WPF application using the .NET Framework 4 Client Profile, the bitmap effect does not appear. If I set the framework version to .NET Framework 3.5 Client Profile (and change no code), it runs as expected. At first, I thought it was a problem in my application, but I removed the code and put it in a separate standalone application and it behaves the same. Anyone else verify that the same problem happens?

What is happening here?

The version 4 framework in VS2010 just seems to ignore the bitmap effect.

<Window.Resources>
    <Style x:Key="SectionHeaderTextBlockStyle" TargetType="{x:Type TextBlock}">
        <Setter Property="FontFamily" Value="Segoe UI"/>
        <Setter Property="FontSize" Value="18"/>
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="Foreground" Value="LightGreen"/>
        <Setter Property="BitmapEffect">
            <Setter.Value>
                <OuterGlowBitmapEffect GlowColor="Black"  GlowSize="3" />
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>

<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
    <TextBlock Text="Contact Details" Style="{DynamicResource SectionHeaderTextBlockStyle}"/>
</Grid>
+1  A: 

BitmapEffects are no longer supported in .NET 4.0.

You should use the Effect property instead.

See here for details.

Patrick Klug
+1  A: 

As stated here by Microsoft, BitmapEffect is obsolete as of .NET 4. Try using Effect instead.

jeffora
A: 

As per this blog post:

5. The BitmapEffect classes are now no-ops.
BitmapEffect used to render in Software and caused perf issues. BitmapEffect are still there so your apps will compile but BitmapEffect will not do anything.

Franci Penov
+3  A: 

As stated by others already: .NET 4.0 no longer supports BitmapEffects.

As an additional info: Since there is no OuterGlowEffect which you can use with the Effect property (at least none that I am aware of), you can replace the bitmap effect with a DropShadowEffect and set its ShadowDepth property to 0. Then you can create a glow effect by adjusting the BlurRadius property. Furthermore, you can also adjust the Color property if you want the glow to have another color than black, but as I see from your code sample, you actually use black as the GlowColor.

I know this workaround might not be as flexible and comfortable as the OuterGlowBitmapEffect and it does not produce identical results, but at least it comes close in some situations, and it is definitely easier than writing a pixel shader yourself...

gehho
Thanks, I've marked this as the answer because you also correctly noticed that the OuterGlowEffect is no longer supported and suggested an alternative.
Adrian
+1: just as a side note: setting the BlurRadius to 0 or -1 will give you something similar but you will not achieve the same look as if you were using the OuterGlowBitmapEffect
Patrick Klug
That's true. And that's what I tried to say with *"might not be as flexible"*. Will edit my answer to be more precise.
gehho
A: 

Have a look at Bitmap Effects which explains some of the issues in using the new GPU based effects.

mikej
A: 

Thanks a lot gehho for the workaround replacing bitmapeffect with this has also given a noticeable performance boost to my application. Cheers.

ashes_onfire
Glad I could help! BTW: Your answer should be a comment to my answer. :)
gehho