I'm starting to kick Silverlight around (although it currently feels the other way around) by rewritting an existing ASP.NET application - as good a place to start as any I thought.
I have 'mastered' pulling data from a database, through a service and into a datagrid and also populating image elements in the rows. So far so good.
Now i'm stuck and have a headache!
I want to add a simple animation (a green rectangle moving over a red rectangle to display a % progress) to the last column of each row, but can't get it wired up.
My xaml looks like this:
<data:DataGrid.Columns>
.
.
.
.
<data:DataGridTemplateColumn>
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel x:Name="AnimationPanel">
<StackPanel.Resources>
<Storyboard x:Key="ShowProgress">
<DoubleAnimation Storyboard.TargetProperty="Width"
Storyboard.TargetName="goalProgressBar_Complete"
From="0" To="50"
Duration="0:0:5">
</DoubleAnimation>
</Storyboard>
</StackPanel.Resources>
<Rectangle x:Name="goalProgressBar_Complete"
Width="1" Height="100"
Fill="#0aa60e"></Rectangle>
</StackPanel>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
</data:DataGrid.Columns>
which is quite obviously wrong (because it doesn't work) and I am starting to think that it just is not possible to add animation to a Datagrid in this way. I've Googled hard looking for a piece of code and while there have been some tantilising results they have not amounted to anything.
Am I trying to do something that Silverlight simply does not support or am I missing something really straightforward?
Thanks in advance.
Edit: Full xaml @ http://daves.stackoverflow.s3.amazonaws.com/stackoverflow.txt
Update: Although I'm not out of the woods yet I have managed to get the animation running with the appropriate column. The answer provided by MasterMax led me to look at EventTriggers and the revised xaml looks like this:
<data:DataGridTemplateColumn>
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Rectangle x:Name="GoalProgress" Height="100" Width="1" Fill="Green">
<Rectangle.Triggers>
<EventTrigger RoutedEvent="Rectangle.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Width"
Storyboard.TargetName="GoalProgress"
From="0" To="50" Duration="0:0:5">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
All I need to do now is bind in the % value in the 'To' property and add my underlying Red rectangle. No doubt this will not prove as easy as I'm currently hoping but then it wouldn't be fun otherwise would it ;-)