internal static AnimationContext PlayIfPossible(this AnimationContext target, Control hostControl) { if (AnimationManager.IsGlobalAnimationEnabled && AnimationManager.GetIsAnimationEnabled(hostControl)) { target.Instance.Begin(); } return(target); }
/// <summary> /// Plays an animation for the given control and invokes the callback on completion. /// </summary> /// <param name="target">The control for which to play the animation.</param> /// <param name="animationName">The name of the animation.</param> /// <param name="completeCallback">The callback to be called. The callback is always called.</param> /// <param name="args">Optional oarameters for the animation, can be provided by the control.</param> /// <returns>True if an aimation actually played, false otherwise.</returns> public static bool Play(FrameworkElement target, string animationName, Action completeCallback, params object[] args) { bool animationsEnabled = AnimationManager.GetIsAnimationEnabled(target) && AnimationManager.IsGlobalAnimationEnabled; if (!animationsEnabled || VisualTreeHelper.GetChildrenCount(target) <= 0) { BeginInvokeCallback(completeCallback, target); return(false); } AnimationSelectorBase selector = null; RadAnimation animation = null; ////FrameworkElement firstChild = VisualTreeHelper.GetChild(target, 0) as FrameworkElement; ////Storyboard storyboard = firstChild.Resources[animationName] as Storyboard; Storyboard storyboard = target.Resources[animationName] as Storyboard; if (storyboard == null) { selector = AnimationManager.GetAnimationSelector(target); if (selector == null) { BeginInvokeCallback(completeCallback, target); return(false); } animation = selector.SelectAnimation(target, animationName); if (animation == null) { BeginInvokeCallback(completeCallback, target); return(false); } storyboard = animation.CreateAnimation(target); if (storyboard == null) { BeginInvokeCallback(completeCallback, target); return(false); } else { storyboard.Completed += new EventHandler(OnStoryboardCompleted); AnimationManager.SetAnimation(storyboard, animation); target.Resources.Add(animationName, storyboard); ////firstChild.Resources.Add(animationName, storyboard); } } RadAnimation sourceAnimation = AnimationManager.GetAnimation(storyboard); AddCallback(storyboard, new Action(() => storyboard.Stop())); if (completeCallback != null) { AddCallback(storyboard, completeCallback); } if (storyboard.Children.Count > 0) { sourceAnimation.UpdateAnimation(target, storyboard, args); } storyboard.Begin(); return(true); }