Dependancy Properties and the Light Fantastic - Silverlight
So the above Silverlight app looks quite nice. Similar to some old school Amiga style demos.
But where this differs is the amount of code required to create it from scratch. If you look at the source there is 'code' but most of it is automatically generated by Visual Studio 2010 when you use the 'propd' snippit.
But before we get on to that lets have, a quick look at what is in the xaml files.
A single pulse is just an ellipse with radial gradient fill with a scale transform all wrapped up in a grid that has a triggered storyboard animating the scale.
The pulse user control is then used within the PulseContainer. The Pulse container has a grid with a collection of pulse user controls, each with a rotate transform.
This also has a triggered storyboard, but this time it rotates the whole grid.
Finally there is the MainPage xaml which has a number of PulseContainer user controls each with a difference radius.
For this demonstration it also has a load of buttons for setting properties, but these are unecessary for non-interactive demonstrations.
As you can see that is all very brief so how does it work?
Now, we can look at the code behind for the Pulse.
Although there are three properties of the Pulse user control they are so similar that we are only seeing one below.
publicColor Shade
{
get { return (Color)GetValue(ShadeProperty); }
set
{
SetValue(ShadeProperty, value);
shader.Color = Shade;
}
}
// Using a DependencyProperty
as the backing store for Shade.This
enables animation, styling, binding, etc...
Setting the type and name automatically updates all the references, all you have to do is change the typeof(ownerclass) to point to your class and change UIPropertyMetadata to PropertyMetadata as Silverlight does not support the standard .NET UIPropertyMetadata.
In fact that is so important I am going to say it again. CHANGE UIPropertyMetadata to PropertyMetadata for Silverlight !!
So, as you can imagine the Radius property sets the Ellipse width and height, with the Delay property setting the BeginTime of the Storyboard.
The PulseContainer has slightly more to it.
The Shade property updates all the child Pulse objects
With the same for ElementRadius and Delay. Radius property here referes to the container radius.
RotateSpeedms updates the storyboard rotating the whole container.
The last Property I added was Arms. This is the number of arms/spokes the container has.
Disclaimer:
This page is by me for me, if you are not me then please be aware of the following
I am not responsible for anything that works or does not work including files and pages made available at slsushi.co.uk, www.jumpstation.co.uk and www.pay4foss.org
I am also not responsible for any information(or what you or others do with it) available at slsushi.co.uk, www.jumpstation.co.uk and www.pay4foss.org
In fact I'm not responsible for anything ever, so there!