Charles Petzold

This Stuff is Trippy

October 28, 2005
A chilly Roscoe, NY

I was fooling around with the RadialGradientBrush on a window background, and I wrote a little program that let me change the brush Center and GradientOrigin properties with left and right mouse clicks, and under certain conditions (making the brush radius about 10% of the window width and height, and setting the SpreadMethod to GradientSpreadMethod.Repeat, and clicking inside the inner circle but towards its border) I got some rather cool effects. The ClickTheGradientCenter.cs program requires standard Avalon references.

Of course, this being Avalon, once you see something like that, you experience an uncontrollable gonzo-programming compulsion to replace the interactive stuff with animation and do it entirely in XAML., and so something like AnimateGradientCenter.xaml results. If you have a recent Avalon beta installed, you should be able to load the XAML file directly into Internet Explorer. (But not, apparently, from the web to IE. Try downloading it first, and then launch it.)

The approach I took in the XAML doesn't entirely please me. I really wanted to rotate the GradientOrigin point around the center, but I couldn't quite get it. I settled instead for moving it in an octagon around the center.