Create Scale With Fade Effects - CSharp Windows.UI.Xaml.Media.Animation

CSharp examples for Windows.UI.Xaml.Media.Animation:Animation

Description

Create Scale With Fade Effects

Demo Code


using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml;
using Windows.UI;
using System;//  ww w  .j a  v  a 2s  . com

public class Main{
        public static Storyboard CreateScaleWithFadeEffects(UIElement target, TimeSpan beginTime, TimeSpan duration,
            double scaleFrom, double scaleTo, double opacityFrom, double opacityTo, EasingFunctionBase easing = null)
        {
            var scaleX = new DoubleAnimation
            {
                BeginTime = beginTime,
                Duration = duration,
                EasingFunction = easing,
                From = scaleFrom,
                To = scaleTo,
            };

            Storyboard.SetTarget(scaleX, target);
            Storyboard.SetTargetProperty(scaleX, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)");

            var scaleY = new DoubleAnimation
            {
                BeginTime = beginTime,
                Duration = duration,
                EasingFunction = easing,
                From = scaleFrom,
                To = scaleTo,
            };

            Storyboard.SetTarget(scaleY, target);
            Storyboard.SetTargetProperty(scaleY, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)");

            var opacityIn = new DoubleAnimation
            {
                BeginTime = beginTime,
                Duration = duration,
                From = opacityFrom,
                To = opacityTo,
            };

            Storyboard.SetTarget(opacityIn, target);
            Storyboard.SetTargetProperty(opacityIn, "Opacity");

            var sb = new Storyboard();
            sb.Children.Add(scaleX);
            sb.Children.Add(scaleY);
            sb.Children.Add(opacityIn);
            return sb;
        }
}

Related Tutorials