/// <summary> /// When sprites are added into the game canvas, if they have storyboards targeting them then /// this method will redirect to the INSTANCE of the target instead of the NAME. /// </summary> /// <param name="uc"></param> public static void RedirectStoryboardTargets(SysWinF.FrameworkElement uc) { foreach (object item in uc.Resources) { #if WINDOWS_PHONE || SILVERLIGHT if (item is System.Collections.DictionaryEntry) { Object itemValue = ((System.Collections.DictionaryEntry)item).Value; #else if (item is System.Collections.Generic.KeyValuePair<object, object>) { Object itemValue = ((System.Collections.Generic.KeyValuePair<object, object>)item).Value; #endif if (itemValue is Storyboard) { Storyboard sb = itemValue as Storyboard; foreach (Timeline tl in sb.Children) { string target = tl.GetValue(Storyboard.TargetNameProperty).ToString(); SysWinF.UIElement targetElement = uc.FindName(target) as SysWinF.UIElement; if (targetElement != null) Storyboard.SetTarget(tl, targetElement); } } } } // now do any children for (int i = 0; i < SysWinMedia.VisualTreeHelper.GetChildrenCount(uc); i++) { SysWinF.DependencyObject child = SysWinMedia.VisualTreeHelper.GetChild(uc, 0); if (child is SysWinF.FrameworkElement) { RedirectStoryboardTargets(child as SysWinF.FrameworkElement); } } }