コード例 #1
0
ファイル: CrossFade.cs プロジェクト: sqdavid/Avalonia
        /// <summary>
        /// Starts the animation.
        /// </summary>
        /// <param name="from">
        /// The control that is being transitioned away from. May be null.
        /// </param>
        /// <param name="to">
        /// The control that is being transitioned to. May be null.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> that tracks the progress of the animation.
        /// </returns>
        public async Task Start(IVisual from, IVisual to)
        {
            var tasks = new List <Task>();

            if (to != null)
            {
                to.Opacity = 0;
            }

            if (from != null)
            {
                tasks.Add(Animate.Property(
                              (IAvaloniaObject)from,
                              Visual.OpacityProperty,
                              from.Opacity,
                              0,
                              LinearEasing.For <double>(),
                              Duration).ToTask());
            }

            if (to != null)
            {
                to.Opacity   = 0;
                to.IsVisible = true;

                tasks.Add(Animate.Property(
                              (IAvaloniaObject)to,
                              Visual.OpacityProperty,
                              0,
                              1,
                              LinearEasing.For <double>(),
                              Duration).ToTask());
            }

            await Task.WhenAll(tasks.ToArray());

            if (from != null)
            {
                from.IsVisible = false;
                from.Opacity   = 1;
            }

            if (to != null)
            {
                to.Opacity = 1;
            }
        }
コード例 #2
0
ファイル: PageSlide.cs プロジェクト: zofuthan/Avalonia
        /// <summary>
        /// Starts the animation.
        /// </summary>
        /// <param name="from">
        /// The control that is being transitioned away from. May be null.
        /// </param>
        /// <param name="to">
        /// The control that is being transitioned to. May be null.
        /// </param>
        /// <param name="forward">
        /// If true, the new page is slid in from the right, or if false from the left.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> that tracks the progress of the animation.
        /// </returns>
        public async Task Start(IVisual from, IVisual to, bool forward)
        {
            var tasks             = new List <Task>();
            var parent            = GetVisualParent(from, to);
            var distance          = Orientation == SlideAxis.Horizontal ? parent.Bounds.Width : parent.Bounds.Height;
            var translateProperty = Orientation == SlideAxis.Horizontal ? TranslateTransform.XProperty : TranslateTransform.YProperty;

            if (from != null)
            {
                var transform = new TranslateTransform();
                from.RenderTransform = transform;
                tasks.Add(Animate.Property(
                              transform,
                              translateProperty,
                              0.0,
                              forward ? -distance : distance,
                              LinearEasing.For <double>(),
                              Duration).ToTask());
            }

            if (to != null)
            {
                var transform = new TranslateTransform();
                to.RenderTransform = transform;
                to.IsVisible       = true;
                tasks.Add(Animate.Property(
                              transform,
                              translateProperty,
                              forward ? distance : -distance,
                              0.0,
                              LinearEasing.For <double>(),
                              Duration).ToTask());
            }

            await Task.WhenAll(tasks.ToArray());

            if (from != null)
            {
                from.IsVisible = false;
            }
        }
コード例 #3
0
 /// <summary>
 /// Returns a new <see cref="PropertyTransition"/> for the specified
 /// <see cref="AvaloniaProperty"/> using linear easing.
 /// </summary>
 /// <typeparam name="T">The type of the <see cref="AvaloniaProperty"/>.</typeparam>
 /// <param name="property">The property to animate.</param>
 /// <param name="duration">The animation duration.</param>
 /// <returns>
 /// A <see cref="PropertyTransition"/> that can be added to the
 /// <see cref="Animatable.PropertyTransitions"/> collection.
 /// </returns>
 public static PropertyTransition Transition <T>(this AvaloniaProperty <T> property, TimeSpan duration)
 {
     return(new PropertyTransition(property, duration, LinearEasing.For <T>()));
 }