|
|
|
@ -11,16 +11,38 @@ namespace Perspex.Animation |
|
|
|
using System.Reactive.Threading.Tasks; |
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Defines a cross-fade animation between two <see cref="IVisual"/>s.
|
|
|
|
/// </summary>
|
|
|
|
public class CrossFade : IPageTransition |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="CrossFade"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="duration">The duration of the animation.</param>
|
|
|
|
public CrossFade(TimeSpan duration) |
|
|
|
{ |
|
|
|
this.Duration = duration; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the duration of the animation.
|
|
|
|
/// </summary>
|
|
|
|
public TimeSpan Duration { get; } |
|
|
|
|
|
|
|
public async Task Start(Visual from, Visual to, bool forward) |
|
|
|
/// <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>(); |
|
|
|
|
|
|
|
@ -32,7 +54,7 @@ namespace Perspex.Animation |
|
|
|
if (from != null) |
|
|
|
{ |
|
|
|
tasks.Add(Animate.Property( |
|
|
|
from, |
|
|
|
(IObservablePropertyBag)from, |
|
|
|
Visual.OpacityProperty, |
|
|
|
from.Opacity, |
|
|
|
0, |
|
|
|
@ -46,7 +68,7 @@ namespace Perspex.Animation |
|
|
|
to.IsVisible = true; |
|
|
|
|
|
|
|
tasks.Add(Animate.Property( |
|
|
|
to, |
|
|
|
(IObservablePropertyBag)to, |
|
|
|
Visual.OpacityProperty, |
|
|
|
0, |
|
|
|
1, |
|
|
|
@ -64,5 +86,25 @@ namespace Perspex.Animation |
|
|
|
|
|
|
|
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">
|
|
|
|
/// Unused for cross-fades.
|
|
|
|
/// </param>
|
|
|
|
/// <returns>
|
|
|
|
/// A <see cref="Task"/> that tracks the progress of the animation.
|
|
|
|
/// </returns>
|
|
|
|
Task IPageTransition.Start(IVisual from, IVisual to, bool forward) |
|
|
|
{ |
|
|
|
return this.Start(from, to); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|