Jerry Nixon on Windows: Shimmer and Shine with WPF4 (and, I suppose, SL)

Friday, July 2, 2010

Shimmer and Shine with WPF4 (and, I suppose, SL)

Shine Wouldn’t it be nice if you had a Button or header or some element that, when your mouse selected it (or moved over it) it would animate a cool looking shine?

Take a look at the image on the right. The top two are just sitting there, while the bottom Button (in this case it’s really just a Border) is animating a shimmer.

The technique simply to animate the offset of a linear gradient that is tilted and applied to the border. It’s crazy easy when you see how I do it.

If there’s a trick, it’s accessing the correct gradient stop. Here’s that syntax:

The other trick is realizing that the gradient stop collection is zero-based. That might get you, too. And they are sorted based on ordinal XAML position and not Offset reference.

Here’s the code.