ALLINSIGHT

Home of the AlmostImplementedException

WPF: How to draw a shadow effect the easy way

As always you will find alot of crapp about shadows in WPF on the internet. And again, here is a HowTo to show you an easy way to do it.

To demonstrate the shadow we’ll use the Pie-Code from my last Post.
Now we’ll just set the shadow effect for one of the pies.

As you can see, the Shadow is drawn like this: Pie with shadow and only for the first pie.

To get the same result with code behind we have to add the using System.Windows.Media.Effects and write the following code:

Now, the second pie-piece have a shadow too. But this one look a little bit diffrent. Thats because of the different angle the shadow is drawn with. The effect calculates that for us.

When you just foul around a little bit, you will notice that the shadow may be drawn over another pie. Thats because we give every pie a shadow.
And here is the beautiful thing about the DropShadowEffect, you can use it on a control which have both pies in it and the shadow is drawn for both pies but handled as one.
Here ist the resulting image: Pie-Chart with shadow

Just add a canvas around our 2 pies and add the DropShadowEffect there. In code behind just set the Effect for the canvas and not the pie.

And thats all you need to know to use the DropShadowEffect to draw a shadow.

Share :

, , ,

Leave a Reply

Your email address will not be published. Required fields are marked *