Targeting Elements in Silverlight
In Silverlight, there are a variety of ways to target elements in Silverlight. For instance, if we want to change the color of a border, we can target it this way:
<Button x:Name="ContactButton" Content="Contact Us">
<Button.BorderBrush>
<SolidColorBrush x:Name="ContactButtonBrush" Color="Red" />
</Button.BorderBrush>
</Button>
The Button has a border brush that's a solid color brush with an added name. This name will be used to target it's Color property, as shown in the storyboard below.
<Storyboard x:Key="ContactButtonStoryboard">
<ColorAnimation Storyboard.TargetName="ContactButtonBrush"
Storyboard.TargetProperty="Color"
Duration="0:0:5"
AutoReverse="True"
To="Yellow" />
</Storyboard>
As you see, the storyboard can target that brush, by linking to it via it's name, and target the Color property. This animation is set to last 5 seconds (using the timespan notation), to auto reverse at the end back to the original color, and change to Yellow and back to Red.
Another way to target elements is via the longer form, as in the following example:
<Border x:Name="PicturesButtonBorder" Background="LightYellow" BorderThickness="1,5,1,5" CornerRadius="10">
<Border.BorderBrush>
<SolidColorBrush Color="Navy" />
</Border.BorderBrush>
</Border>
<ColorAnimation Duration="0:0:1" To="Navy"
Storyboard.TargetName="PicturesButtonBorder"
Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"/>
Notice that in this example, the solid color brush does not have a name, but the animation targets the border itself. The long hand form is simply this:
(ElementType.PropertyName)
The first value is the type of element (border and solidcolorbrush), and the second property after the period (borderbrush and color) specify the properties. These notations can be strung together to drill down through the various complex properties. You can even access elements via an index like [0].
So these two options create more flexibility for you in targeting properties (not just for animations, but elsewhere as well).