How do you handle a button click as the routed event in an event trigger in Silverlight 1.0 Beta? You don't, according to the RoutedEvent Property documentation. The only event supported in event triggers is the Loaded event. I can write the following XAML.
<Canvas.Triggers>
<EventTrigger RoutedEvent="Canvas.MouseLeftButtonDown">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="createdBy" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:01.25" Value="0.3"/>
<SplineDoubleKeyFrame KeyTime="00:00:01.90" Value="0.75"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Canvas.Triggers>
But, I can't use it in Silverlight 1.0 Beta. Loading the page containing the control that hosts this XAML produces an error like this one.
The work-around is to move this into a resource block and invoke it programmatically, like so.
<Canvas.Resources>
<Storyboard x:Name="fadeInStoryboard">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="createdBy" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:01.25" Value="0.3"/>
<SplineDoubleKeyFrame KeyTime="00:00:01.90" Value="0.75"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Canvas.Resources>
function onMouseLeftButtonDown(sender, eventArgs)
{
var fadeInStoryboard= sender.findName("fadeInStoryboard");
fadeInStoryboard.begin();
}
Silverlight 1.1 has better support for XAML-based behaviors but is currently in Alpha.