Пример #1
0
 public static PropertyTransition Transition <T>(this PerspexProperty <T> property, TimeSpan duration)
 {
     return(new PropertyTransition
     {
         Property = property,
         Duration = duration,
         Easing = LinearEasing.For <T>(),
     });
 }
Пример #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(
                              (IPerspexObject)from,
                              Visual.OpacityProperty,
                              from.Opacity,
                              0,
                              LinearEasing.For <double>(),
                              Duration).ToTask());
            }

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

                tasks.Add(Animate.Property(
                              (IPerspexObject)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;
            }
        }
Пример #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 = parent.Bounds.Width;

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

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

            if (from != null)
            {
                from.IsVisible = false;
            }
        }
Пример #4
0
 /// <summary>
 /// Returns a new <see cref="PropertyTransition"/> for the specified
 /// <see cref="PerspexProperty"/> using linear easing.
 /// </summary>
 /// <typeparam name="T">The type of the <see cref="PerspexProperty"/>.</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 PerspexProperty <T> property, TimeSpan duration)
 {
     return(new PropertyTransition(property, duration, LinearEasing.For <T>()));
 }