Exemplo n.º 1
0
 private void OnAnimationAdded(RadAnimation radAnimation)
 {
     if (radAnimation.AnimationName != null)
     {
         this.availableAnimations.Add(radAnimation.AnimationName, radAnimation);
     }
 }
Exemplo n.º 2
0
 private void OnAnimationRemoved(RadAnimation radAnimation)
 {
     if (this.availableAnimations.ContainsKey(radAnimation.AnimationName))
     {
         this.availableAnimations.Remove(radAnimation.AnimationName);
     }
 }
        /// <summary>
        /// Updates the slide animation.
        /// </summary>
        /// <param name="control">The control for which the animation needs to be updated.</param>
        /// <param name="storyboard">Storyvoard that needs to be updated.</param>
        /// <param name="target">The targeted element of the animation.</param>
        /// <param name="args"></param>
        /// <remarks>
        /// Currently the method sets the SpeedRatio of the storyboard to
        /// the global <strong>AnimationSpeedRatio</strong> if the local SpeedRatio is null.
        /// If the local SpeedRatio value is set, it will be used.
        /// </remarks>
        protected override void UpdateAnimationOverride(FrameworkElement control, Storyboard storyboard, FrameworkElement target, params object[] args)
        {
            this.UpdateSlideMode(target, args);

            if (target.ActualHeight == 0)
            {
                // TODO: Discuss LayoutUpdate here.
                target.UpdateLayout();
            }

            var value = target.ActualHeight;

            var nonZeroValue = this.SlideMode == SlideMode.Top ? 1.0 : -1.0;
            var relativeFrom = this.GetValueDependingOnDirection(nonZeroValue, 0.0);
            var relatoveTo   = this.GetValueDependingOnDirection(0.0, nonZeroValue);

            value *= -1 * nonZeroValue;
            var fromValue = this.GetValueDependingOnDirection(value, 0.0);
            var endValue  = this.GetValueDependingOnDirection(0.0, value);

            var duration = RadAnimation.GetDurationSecondsForLength(Math.Abs(value));

            var splineToUse = this.GetValueDependingOnDirection(Easings.SlideDown1, Easings.SlideUp1);

            storyboard.Update()
            .Animate(target)
            .OpacityMaskRelativeMoveY(0, relativeFrom, duration, relatoveTo)
            .Easings(splineToUse)
            .MoveY(0, fromValue, duration, endValue)
            .Easings(splineToUse);

            DisableControlWhileAnimationIsRunning(target, storyboard);
        }
Exemplo n.º 4
0
 internal static void SetAnimation(DependencyObject obj, RadAnimation value)
 {
     if (value == null)
     {
         obj.SetValue(AnimationProperty, null);
     }
     else
     {
         obj.SetValue(AnimationProperty, new WeakReference(value));
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Updates the slide animation.
        /// </summary>
        /// <param name="control">The control for which the animation needs to be updated.</param>
        /// <param name="storyboard">Storyvoard that needs to be updated.</param>
        /// <param name="target">The targeted element of the animation.</param>
        /// <param name="args"></param>
        /// <remarks>
        /// Currently the method sets the SpeedRatio of the storyboard to
        /// the global <strong>AnimationSpeedRatio</strong> if the local SpeedRatio is null.
        /// If the local SpeedRatio value is set, it will be used.
        /// </remarks>
        protected override void UpdateAnimationOverride(FrameworkElement control, Storyboard storyboard, FrameworkElement target, params object[] args)
        {
            var relativeFrom =
                this.GetValueDependingOnDirection(this.MinOpacity, this.MaxOpacity);
            var relativeTo =
                this.GetValueDependingOnDirection(this.MaxOpacity, this.MinOpacity);

            var duration = RadAnimation.GetDurationSecondsForLength(200.0);

            storyboard.Update()
            .Animate(target)
            .Opacity(0, relativeFrom, duration, relativeTo)
            .Easings(this.Easing)
            .AdjustSpeed();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Updates the slide animation.
        /// </summary>
        /// <param name="control">The control for which the animation needs to be updated.</param>
        /// <param name="storyboard">Storyvoard that needs to be updated.</param>
        /// <param name="target">The targeted element of the animation.</param>
        /// <param name="args"></param>
        /// <remarks>
        /// Currently the method sets the SpeedRatio of the storyboard to
        /// the global <strong>AnimationSpeedRatio</strong> if the local SpeedRatio is null.
        /// If the local SpeedRatio value is set, it will be used.
        /// </remarks>
        protected override void UpdateAnimationOverride(FrameworkElement control, Storyboard storyboard, FrameworkElement target, params object[] args)
        {
            var relativeFrom =
                this.GetValueDependingOnDirection(this.MinScale, this.MaxScale);
            var relativeTo =
                this.GetValueDependingOnDirection(this.MaxScale, this.MinScale);

            var duration = RadAnimation.GetDurationSecondsForLength(100.0);

            storyboard.Update()
            .Animate(target)
            .EnsureDefaultTransforms()
            .ScaleX(0, relativeFrom, duration, relativeTo)
            .Easings(this.Easing)
            .ScaleY(0, relativeFrom, duration, relativeTo)
            .Easings(this.Easing)
            .AdjustSpeed();
        }
Exemplo n.º 7
0
        /// <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);
        }