2using System.Runtime.ExceptionServices;
4using System.Threading.Tasks;
5using Microsoft.Maui.ApplicationModel;
6using Microsoft.Maui.Controls;
15 private readonly
double? fromOpacity;
16 private readonly
double toOpacity;
28 if (ToOpacity < 0 || ToOpacity > 1)
29 throw new ArgumentOutOfRangeException(nameof(ToOpacity),
"Opacity must be between 0 and 1.");
30 if (FromOpacity.HasValue && (FromOpacity.Value < 0 || FromOpacity.Value > 1))
31 throw new ArgumentOutOfRangeException(nameof(FromOpacity),
"Opacity must be between 0 and 1.");
33 this.fromOpacity = FromOpacity;
34 this.toOpacity = ToOpacity;
40 ArgumentNullException.ThrowIfNull(Target);
41 ArgumentNullException.ThrowIfNull(Context);
45 Target.Opacity = this.toOpacity;
49 if (this.fromOpacity.HasValue)
50 Target.Opacity = this.fromOpacity.Value;
53 Func<CancellationToken, Task> Execute =
_ => Target.FadeToAsync(this.toOpacity, DurationMs, this.
Easing);
54 ExceptionDispatchInfo? DispatchInfo =
null;
61 DispatchInfo = ExceptionDispatchInfo.Capture(Ex);
65 await this.ApplyFinalOpacityAsync(Target);
68 DispatchInfo?.Throw();
71 private Task ApplyFinalOpacityAsync(VisualElement Target)
73 return MainThread.InvokeOnMainThreadAsync(() =>
75 Target.Opacity = this.toOpacity;
Options applied for an individual animation execution.
bool ForceMotion
Gets or sets a value indicating whether motion should run even when global settings request reduced m...
Helper class providing consistent animation execution semantics.
static async Task RunAsync(VisualElement Target, Func< CancellationToken, Task > Execute, CancellationToken Token)
Executes an animation while wiring cancellation tokens to MAUI animation APIs.
Represents an opacity animation.
override async Task RunAsync(VisualElement Target, IAnimationContext Context, AnimationOptions? Options, CancellationToken Token)
Executes the animation against the specified target. Task tracking execution.
FadeAnimation(TimeSpan Duration, Easing Easing, double? FromOpacity, double ToOpacity)
Initializes a new instance of the FadeAnimation class.
Base class providing timing helpers for view animations.
uint ResolveDurationMilliseconds(IAnimationContext Context, AnimationOptions? Options)
Resolves the duration expressed in milliseconds.
Easing Easing
Gets the base easing.
Represents contextual information required when executing an animation.
bool ReduceMotion
Gets a value indicating whether the caller requests reduced motion.