Create Hide Storyboard - CSharp Windows.UI.Xaml.Media.Animation

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

Description

Create Hide Storyboard

Demo Code


using System.Windows.Media.Animation;
using System.Windows;
using System;// ww w . j  av a 2 s .  co  m

public class Main{
        public static Storyboard CreateHideStoryboard(UIElement target, TimeSpan duration)
        {
            var opacityAnimation = new DoubleAnimation
            {
                To = 0.0,
                Duration = duration,
                EasingFunction = new CubicEase {EasingMode = EasingMode.EaseOut}
            };

            Storyboard.SetTarget(opacityAnimation, target);
            Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity"));

            var visibilityAnimation = new ObjectAnimationUsingKeyFrames();
            visibilityAnimation.KeyFrames.Add(new DiscreteObjectKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(duration),
                Value = Visibility.Collapsed
            });

            Storyboard.SetTarget(visibilityAnimation, target);
            Storyboard.SetTargetProperty(visibilityAnimation, new PropertyPath("Visibility"));

            var sb = new Storyboard();
            sb.Children.Add(opacityAnimation);
            sb.Children.Add(visibilityAnimation);

            return sb;
        }
}

Related Tutorials