private IAnimationSettings GetAnimationSettings() { if (BasedOn is CompoundSettings compound) { // Make sure to capture an override on the Event property (if any) if (Event != AnimationSettings.DEFAULT_EVENT) { compound.Event = Event; } return(compound); } var current = new AnimationSettings() { Kind = Kind, Duration = Duration, Delay = Delay, Opacity = Opacity, OffsetX = OffsetX, OffsetY = OffsetY, ScaleX = ScaleX, ScaleY = ScaleY, Rotation = Rotation, BlurRadius = BlurRadius, TransformCenterPoint = TransformCenterPoint, Easing = Easing, EasingMode = EasingMode, Event = Event, #if __UWP__ OffsetZ = OffsetZ, ScaleZ = ScaleZ, Saturation = Saturation, Tint = Tint, #endif }; // If "BasedOn" is used, return an AnimationSettings // object that uses the values in "BasedOn" and then // overrides those with updated values from "current" return(BasedOn == null ? current : ((AnimationSettings)BasedOn)?.ApplyOverrides(current)); }
private static void RunAnimation(FrameworkElement element, AnimationSettings settings, bool runFromIdle, bool isSequence = false) { var timeline = new Timeline(); var iterationBehavior = GetIterationBehavior(element); var iterationCount = GetIterationCount(element); // FADE IN/OUT if (settings.Kind.HasFlag(AnimationKind.FadeTo)) { element.FadeTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.FadeFrom)) { element.FadeFrom(settings, ref timeline); } // ROTATE TO/FROM if (settings.Kind.HasFlag(AnimationKind.RotateTo)) { element.RotateTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.RotateFrom)) { element.RotateFrom(settings, ref timeline); } // SCALE TO/FROM if (settings.Kind.HasFlag(AnimationKind.ScaleXTo)) { element.ScaleXTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.ScaleXFrom)) { element.ScaleXFrom(settings, ref timeline); } if (settings.Kind.HasFlag(AnimationKind.ScaleYTo)) { element.ScaleYTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.ScaleYFrom)) { element.ScaleYFrom(settings, ref timeline); } #if __UWP__ if (settings.Kind.HasFlag(AnimationKind.ScaleZTo)) { element.ScaleZTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.ScaleZFrom)) { element.ScaleZFrom(settings, ref timeline); } #endif // TRANSLATE TO/FROM if (settings.Kind.HasFlag(AnimationKind.TranslateXTo)) { element.TranslateXTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.TranslateXFrom)) { element.TranslateXFrom(settings, ref timeline); } if (settings.Kind.HasFlag(AnimationKind.TranslateYTo)) { element.TranslateYTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.TranslateYFrom)) { element.TranslateYFrom(settings, ref timeline); } #if __UWP__ if (settings.Kind.HasFlag(AnimationKind.TranslateZTo)) { element.TranslateZTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.TranslateZFrom)) { element.TranslateZFrom(settings, ref timeline); } #endif // BLUR TO/FROM if (settings.Kind.HasFlag(AnimationKind.BlurTo)) { element.BlurTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.BlurFrom)) { element.BlurFrom(settings, ref timeline); } ActiveTimeline <Timeline> active = null; if (runFromIdle) { // If the animation is running for an "idle" ActiveTimeline, // then it must be set to the existing ActiveTimeline // instead of creating a new one var guid = GetElementGuid(element); active = _actives.SetTimeline(guid, timeline); } else { // Add the new ActiveTimeline active = _actives.Add(timeline, settings, element, AnimationState.Idle, iterationBehavior, iterationCount, isSequence); } // We decrement the iteration count right before running the animation if (active.IterationCount > 0) { active.IterationCount--; } StartTimeline(timeline); }
internal static void RunAnimation(FrameworkElement element, AnimationSettings settings, bool isSequence = false) { RunAnimation(element, settings, runFromIdle: false, isSequence: isSequence); }
private static void RunAnimation(FrameworkElement element, AnimationSettings settings, bool runFromIdle, bool isSequence = false) { #if !__WPF__ if (Debugger.IsAttached && GetEnableDebugging(element) == DebugTarget.RunAnimation) { Debugger.Break(); } #endif var timeline = new Timeline(); var iterationBehavior = GetIterationBehavior(element); var iterationCount = GetIterationCount(element); // FADE IN/OUT if (settings.Kind.HasFlag(AnimationKind.FadeTo)) { element.FadeTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.FadeFrom)) { element.FadeFrom(settings, ref timeline); } // ROTATE TO/FROM if (settings.Kind.HasFlag(AnimationKind.RotateTo)) { element.RotateTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.RotateFrom)) { element.RotateFrom(settings, ref timeline); } // ColorAnimation supported only on Uno and WPF (not on native UWP due to Composition-only implementations) #if WINDOWS_UWP || HAS_UNO || __WPF__ // COLOR TO/FROM if (settings.Kind.HasFlag(AnimationKind.ColorTo)) { element.ColorTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.ColorFrom)) { element.ColorFrom(settings, ref timeline); } #endif // SCALE TO/FROM if (settings.Kind.HasFlag(AnimationKind.ScaleXTo)) { element.ScaleXTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.ScaleXFrom)) { element.ScaleXFrom(settings, ref timeline); } if (settings.Kind.HasFlag(AnimationKind.ScaleYTo)) { element.ScaleYTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.ScaleYFrom)) { element.ScaleYFrom(settings, ref timeline); } #if __UWP__ if (settings.Kind.HasFlag(AnimationKind.ScaleZTo)) { element.ScaleZTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.ScaleZFrom)) { element.ScaleZFrom(settings, ref timeline); } #endif // TRANSLATE TO/FROM if (settings.Kind.HasFlag(AnimationKind.TranslateXTo)) { element.TranslateXTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.TranslateXFrom)) { element.TranslateXFrom(settings, ref timeline); } if (settings.Kind.HasFlag(AnimationKind.TranslateYTo)) { element.TranslateYTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.TranslateYFrom)) { element.TranslateYFrom(settings, ref timeline); } #if __UWP__ if (settings.Kind.HasFlag(AnimationKind.TranslateZTo)) { element.TranslateZTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.TranslateZFrom)) { element.TranslateZFrom(settings, ref timeline); } #endif #if __WPF__ || __UWP__ // BLUR TO/FROM if (settings.Kind.HasFlag(AnimationKind.BlurTo)) { element.BlurTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.BlurFrom)) { element.BlurFrom(settings, ref timeline); } #endif #if __UWP__ // SATURATE TO/FROM if (settings.Kind.HasFlag(AnimationKind.SaturateTo)) { element.SaturateTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.SaturateFrom)) { element.SaturateFrom(settings, ref timeline); } // TINT TO/FROM if (settings.Kind.HasFlag(AnimationKind.TintTo)) { element.TintTo(settings, ref timeline); } else if (settings.Kind.HasFlag(AnimationKind.TintFrom)) { element.TintFrom(settings, ref timeline); } #endif ActiveTimeline <Timeline> active = null; if (runFromIdle) { // If the animation is running for an "idle" ActiveTimeline, // then it must be set to the existing ActiveTimeline // instead of creating a new one var guid = GetElementGuid(element); active = _actives.SetTimeline(guid, timeline); } else { // Add the new ActiveTimeline active = _actives.Add(timeline, settings, element, AnimationState.Idle, iterationBehavior, iterationCount, isSequence); } // We decrement the iteration count right before running the animation if (active.IterationCount > 0) { active.IterationCount--; } StartTimeline(timeline); }
public static void SetStartWith(DependencyObject obj, AnimationSettings value) => obj.SetValue(StartWithProperty, value);
public static void SetItems(ListViewBase obj, AnimationSettings value) => obj.SetValue(ItemsProperty, value);
internal static void Validate(FrameworkElement element) { // Skip validation if a debugger isn't attached if (!Debugger.IsAttached) { return; } var startWith = element.ReadLocalValue(StartWithProperty); var startWithSettings = GetStartWith(element); var primary = element.ReadLocalValue(PrimaryProperty); var primaryBinding = element.ReadLocalValue(PrimaryBindingProperty); var secondary = element.ReadLocalValue(SecondaryProperty); var secondaryBinding = element.ReadLocalValue(SecondaryBindingProperty); var isIterating = GetIterationBehavior(element) == IterationBehavior.Forever || GetIterationCount(element) > 1; AnimationSettings primarySettings = null; CompoundSettings primaryCompoundSettings = null; AnimationSettings secondarySettings = null; CompoundSettings secondaryCompoundSettings = null; if (GetPrimary(element) is CompoundSettings compoundPrimary) { primaryCompoundSettings = compoundPrimary; } else { primarySettings = GetPrimary(element) as AnimationSettings; } if (GetSecondary(element) is CompoundSettings compoundSecondary) { secondaryCompoundSettings = compoundSecondary; } else { secondarySettings = GetSecondary(element) as AnimationSettings; } // Cannot set an animation for Secondary when specifying values for IterationCount or IterationBehavior. if (isIterating && secondary != DependencyProperty.UnsetValue) { throw new ArgumentException($"Cannot set an animation for {nameof(SecondaryProperty)} when specifying values for {nameof(IterationCountProperty)} or {nameof(IterationBehaviorProperty)}."); } // Primary must be set first before specifying a value for Secondary. if (primary == DependencyProperty.UnsetValue && secondary != DependencyProperty.UnsetValue) { throw new ArgumentException($"{nameof(PrimaryProperty)} must be set first before specifying a value for {nameof(SecondaryProperty)}."); } // PrimaryBinding was set wtihout a corresponding value for Primary. if (primaryBinding != DependencyProperty.UnsetValue && primary == DependencyProperty.UnsetValue) { throw new ArgumentException($"{nameof(PrimaryBindingProperty)} was set wtihout a corresponding value for {nameof(PrimaryProperty)}."); } // Primary is missing a trigger by an event or binding. if (primary != DependencyProperty.UnsetValue && primaryBinding == DependencyProperty.UnsetValue && primarySettings != null && primarySettings?.Event == EventType.None) { throw new ArgumentException($"{nameof(PrimaryProperty)} is missing a trigger by an event or binding."); } // SecondaryBinding was set wtihout a corresponding value for Secondary. if (secondaryBinding != DependencyProperty.UnsetValue && secondary == DependencyProperty.UnsetValue) { throw new ArgumentException($"{nameof(SecondaryBindingProperty)} was set wtihout a corresponding value for {nameof(SecondaryProperty)}."); } // Secondary is missing a trigger by an event or binding. if (secondary != DependencyProperty.UnsetValue && secondaryBinding == DependencyProperty.UnsetValue && secondarySettings != null && secondarySettings.Event == EventType.None) { throw new ArgumentException($"{nameof(SecondaryProperty)} is missing a trigger by an event or binding."); } // Cannot use StartWith without specifying a Primaryanimation. if (startWith != DependencyProperty.UnsetValue && primary == DependencyProperty.UnsetValue) { throw new ArgumentException($"Cannot use {nameof(StartWithProperty)} without specifying a {nameof(PrimaryProperty)} animation."); } }