I know little of WPF but in Silverlight or WP7 the children of a Storyboard
are of type TimeLine
. Also a StoryBoard itself would have a Completed
event to which you would be binding. So at least the first chunk of the code would look like:-
private void storyboard_Completed(object sender, EventArgs e)
{
Storyboard sb = (Storyboard)sender;
DoubleAnimation completedAnimation = (DoubleAnimation)sb.Children[0];
Now for the tricky bit.
Its actually quite unusual for Storyboard.SetTarget
to be used in Silverlight code. I guess that game code is more likely to generate elements and animations in code and therefore more likely to use SetTarget
. If this is what you want to do then you will need to build your own attached property that has both Get and Set, have the changed callback on this property call the Storyboard.SetTarget
.
Here is the code:-
public static class StoryboardServices
{
public static DependencyObject GetTarget(Timeline timeline)
{
if (timeline == null)
throw new ArgumentNullException("timeline");
return timeline.GetValue(TargetProperty) as DependencyObject;
}
public static void SetTarget(Timeline timeline, DependencyObject value)
{
if (timeline == null)
throw new ArgumentNullException("timeline");
timeline.SetValue(TargetProperty, value);
}
public static readonly DependencyProperty TargetProperty =
DependencyProperty.RegisterAttached(
"Target",
typeof(DependencyObject),
typeof(Timeline),
new PropertyMetadata(null, OnTargetPropertyChanged));
private static void OnTargetPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Storyboard.SetTarget(d as Timeline, e.NewValue as DependencyObject);
}
}
Now the SetTarget
code would become:-
StoryboardServices.SetTarget(completedAnimation, bomb);
Then your completed event can retrieve the target with:-
Bomb completedBomb = (Bomb)StoryboardServices.GetTarget(completedAnimation);