Today a fast and easy tip about shadows and performance.
In a project I have recently made, we've told the designer not to use BitmapEffects because they are performance killer. He so decided to create it's own shadows by duplicating each shape and make them looks like shadows(designer magic, voodoo things, etc...). I was then surprised to see that it kills performance too !
There is still the shaders effect which came with the 3.5 SP1 framework but they will be available only on vista or greater plateforms and their performance will depend of your graphic cards.
But we have an another ace in you deck : the system shadow which are quite fast even on software rendering!
Using it is quite easy :
- Add the PresentationFramework.Aero reference to your project,
- Add the following XML namespace : ”clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero”,
- Use the SystemDropShadowChrome element available with this namespace !
But there is a drawback : you can only produce squared shadows. But you can still play with the CornerRadius property to create simily round shadows.
Here is a little example of XAML code:
<UniformGrid xmlns:shadows="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" Columns="2"> <shadows:SystemDropShadowChrome Margin="25"> <ListBox> <ListBoxItem Content="One item" /> <ListBoxItem Content="Another item" /> <ListBoxItem Content="Another third item" /> </ListBox> </shadows:SystemDropShadowChrome > <shadows:SystemDropShadowChrome Margin="25" CornerRadius="800" Width="100" Height="100"> <Ellipse Stroke="Black" Fill="White" /> </shadows:SystemDropShadowChrome> </UniformGrid>