void ReplaceStaticAnimationTargets(Animation animation)
{
if(animation == null)
return;
// Check if the Animation has an AnimationTarget property, but not AnimationTargetScript
// or TargetScript properties
string id;
string script;
if((animation.Properties.TryGetValue("AnimationTarget", out id) && !String.IsNullOrEmpty(id)) &&
(!animation.Properties.TryGetValue("AnimationTargetScript", out script) || String.IsNullOrEmpty(script)) &&
(!animation.Properties.TryGetValue("TargetScript", out script) || String.IsNullOrEmpty(script))) {
// Remove the AnimationTarget property and replace it with a dynamic wrapper
animation.Properties.Remove("AnimationTarget");
animation.Properties["TargetScript"] = String.Format(CultureInfo.InvariantCulture, "$get('{0}')", id);
}
// Replace any static animation targets on this Animation's children
foreach(Animation child in animation.Children)
ReplaceStaticAnimationTargets(child);
}