Have you heard? The guys at Redmond impressed the world once again! .Net 3.5 SP1 is now Beta…. If you didn’t already, I would suggest that you read this brilliant post from Tim Sneath to get more info on what’s new in WPF.
Today, I wanted to experiment a bit with the new Effects that were included in the SP1 Beta. These effects are the same as the BitmapEffects that were previously in WPF. One can also say that these are the replacement for the BitmapEffects. Why? Simple. BitmapEffect are slow, these are NOT! BitmapEffects are fully software rendered while the new Effects take advantage of the machine’s GPU. Well this is not exactly right there are instances where this does not apply…
- When the graphics card being run on does not support PixelShader 2.0 or above. This is becoming more and more rare, but is definitely still out there.
- When the WPF application is being remoted over Remote Desktop or Terminal Server or some other kind of mirror driver.
- When the WPF application is in a mode where software rendering is required – such as rendering to a RenderTargetBitmap, or printing.
(this was taken from this post, well copies and pasted if I might. How would I know such a thing after all😀 )
Ok, so what can you do with these effects? something like this as starters….
In the sample application I used the DropShadowEffect and the BlurEffect, and then I combined the 2 together. One of the cool things with these effects is that the properties are Dependency properties i.e we can databind the properties values.
It is very easy to apply an effect to an element. All you have to do is to set the Effect property like so
One thing that is worth mentioning is that you cannot apply more than one effect to a UIElement. Yet we can workaround this by having a wrapper element(ex: Border) and set the other Effect on the wrapper element. Something like this
Dr.WPF pointed out that WPF SP1 will upconvert the legacy BitmapEffects so that those effects run on the new accelerated pipeline. This will happen wherever possible. It will not happen if the effect is placed within a BitmapEffectGroup because the new pipeline supports only single effects.
For example, if a single BlurBitmapEffect has been applied to an element, SP1 will automatically use a BlurEffect on the element instead so that the blur is hardware accelerated (This upconversion will happen as long as the Radius value is between 0 and some acceptable value). Similarly, a single DropShadowBitmapEffect will be treated as a DropShadowEffect in SP1 whenever possible (This upconversion will happen as long as the Noise property is 0). Certain effects from the old pipeline will never be accelerated in the new pipeline. These include BevelBitmapEffect, OuterGlowBitmapEffect, and EmbossBitmapEffect.
Thanks Dr. We would be lost without you.
I would suggest to read this series of posts to get to know effects better.
Have load of fun!