/// <summary> /// Reacts to a change in a <see cref="PerspexProperty"/> 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(PerspexPropertyChangedEventArgs 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); } } }
/// <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; } }
/// <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; } }