#561 – Drawing a 3D Donut Using a Radial Gradient
May 18, 2012 3 Comments
Here’s another visual effect that you can easily create in WPF and Blend, using a gradient.
Let’s say that you want to draw a ring or donut-shaped object that looks 3D. You can start by using the Ellipse shape to draw a circle.
Next, set the Fill property of the Ellipse to use a radial gradient. Define five gradient stops, as shown, and use the gradient tool to position them as shown.
For the hole in the middle of the donut, you can use an opacity mask. Use a paint program to create an opaque circle that is the same size as the circle, but with a smaller transparent circle in its center. (Trick: Run your app and screen capture what you have so far, then tweak it in a paint program). Finally, set this image as the OpacityMask of the Ellipse.
<Ellipse.OpacityMask> <ImageBrush ImageSource="Images\Mask.png"/> </Ellipse.OpacityMask>