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

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

Description

Create Translate Y With Fade Effects

Demo Code


using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml;
using Windows.UI;
using System;/*from w w w . ja  v  a 2 s . com*/

public class Main{
        public static Storyboard CreateTranslateYWithFadeEffects(UIElement target, TimeSpan beginTime, TimeSpan duration, double from, double to, double opacityFrom = 1, double opacityTo = 0)
        {
            var t1 = new DoubleAnimation
            {
                BeginTime = beginTime,
                Duration = duration,
                To = to,
                EasingFunction = new PowerEase { Power = 2.5 },
            };

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

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

            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