Esempio n. 1
0
        /// <summary>
        /// Reacts to a change in a <see cref="AvaloniaProperty"/> value in order to animate the
        /// change if a <see cref="PropertyTransition"/> is set for the property..
        /// </summary>
        /// <param name="e">The event args.</param>
        protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e)
        {
            if (e.Priority != BindingPriority.Animation && _propertyTransitions != null)
            {
                var match = _propertyTransitions.FirstOrDefault(x => x.Property == e.Property);

                if (match != null)
                {
                    Animate.Property(this, e.Property, e.OldValue, e.NewValue, match.Easing, match.Duration);
                }
            }
        }
Esempio n. 2
0
        /// <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;
            }
        }
Esempio n. 3
0
        /// <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;
            }
        }