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

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

Description

Create Translate X With Fade Effects

Demo Code


using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml;
using Windows.UI;
using System;//from   w w w  .  j  a va  2 s .  co m

public class Main{
        public static Storyboard CreateTranslateXWithFadeEffects(UIElement target, TimeSpan beginTime, TimeSpan duration, double from, double to, double opacityFrom = 0, double opacityTo = 1, EasingFunctionBase easing = null)
        {
            target.Opacity = opacityFrom;

            var t1 = new DoubleAnimation
            {
                BeginTime = beginTime,
                Duration = duration,
                To = to,
                EasingFunction = easing,
            };

            if (from >= 0)
            {
                t1.From = from;
            }

            Storyboard.SetTarget(t1, target);
            Storyboard.SetTargetProperty(t1, "(UIElement.RenderTransform).(CompositeTransform.TranslateX)");


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

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

            var sb = new Storyboard();
            sb.Children.Add(t1);
            sb.Children.Add(opacity);
            return sb;
        }
}

Related Tutorials