public static void BeginAnimation(this IAnimatable animatable, DependencyProperty dependencyProperty, AnimationTimeline animation, HandoffBehavior handoffBehavior = HandoffBehavior.SnapshotAndReplace, object layerOwner = null) { AnimationTimelineClock animationClock = (AnimationTimelineClock)animation.CreateClock(); animatable.ApplyAnimationClock(dependencyProperty, animationClock, handoffBehavior, layerOwner); animationClock.Begin(animatable.RootClock); }
private TargetKey GetClockTarget(AnimationTimelineClock clock, FrameworkElement containingObject, INameScope nameScope) { DependencyObject root = GetTarget(clock.Timeline); if (root == null) { string targetName = GetTargetName(clock.Timeline); if (targetName.IsNullOrEmpty()) { root = containingObject; } else { root = nameScope.FindName(targetName) as DependencyObject; if (root == null) { throw new Granular.Exception("Can't find Storyboard.TargetName \"{0}\" for element \"{1}\"", targetName, containingObject); } } } PropertyPath propertyPath = GetTargetProperty(clock.Timeline); DependencyObject target; DependencyProperty targetProperty; return(TryGetPropertyPathTarget(root, propertyPath, out target, out targetProperty) && target is IAnimatable ? new TargetKey((IAnimatable)target, targetProperty) : null); }
private void GetAnimationClocksTargets(TimelineClock clock, FrameworkElement containingObject, INameScope nameScope, ref ListDictionary <TargetKey, AnimationTimelineClock> targets) { AnimationTimelineClock animationClock = clock as AnimationTimelineClock; if (animationClock != null) { TargetKey target = GetClockTarget(animationClock, containingObject, nameScope); if (target != null) { targets.Add(target, animationClock); } } TimelineGroupClock clockGroup = clock as TimelineGroupClock; if (clockGroup != null) { foreach (TimelineClock child in clockGroup.Children) { GetAnimationClocksTargets(child, containingObject, nameScope, ref targets); } } }
public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationTimelineClock animationClock) { double progress = EasingFunction != null?EasingFunction.Ease(animationClock.CurrentState.Progress) : animationClock.CurrentState.Progress; double?baseValue = animationOperations.Zero; double?from; double?to; if (this.From != null) { if (this.To != null) { if (IsAdditive && isAccumulable) { baseValue = (double?)defaultOriginValue; } from = this.From; to = this.To; } else if (this.By != null) { if (IsAdditive && isAccumulable) { baseValue = (double?)defaultOriginValue; } from = this.From; to = animationOperations.Add(this.From, this.By); } else { from = this.From; to = (double?)defaultDestinationValue; } } else if (this.To != null) { from = (double?)defaultOriginValue; to = this.To; } else if (this.By != null) { if (isAccumulable) { baseValue = (double?)defaultOriginValue; } from = animationOperations.Zero; to = this.By; } else { from = (double?)defaultOriginValue; to = (double?)defaultDestinationValue; } if (IsCumulative && isAccumulable) { baseValue = animationOperations.Add(baseValue, animationOperations.Scale(animationOperations.Subtract(to, from), Math.Floor(animationClock.CurrentState.Iteration))); } return(animationOperations.Add(baseValue, animationOperations.Interpolate(from, to, progress))); }
public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationTimelineClock animationClock) { if (KeyFrames.Count == 0) { return(defaultDestinationValue); } TimeSpan duration = Duration.HasTimeSpan ? Duration.TimeSpan : GetKeyFramesDuration(); TimeSpan time = duration.Scale(animationClock.CurrentState.Progress); int index = GetKeyFrameIndexAtTime(time, duration); double?value; if (index == KeyFrames.Count) { value = KeyFrames[KeyFrames.Count - 1].Value; } else { double?baseValue; if (index == 0) { baseValue = IsAdditive && isAccumulable ? animationOperations.Zero : (double?)defaultOriginValue; } else { baseValue = KeyFrames[index - 1].Value; } TimeSpan segmentStart = index == 0 ? TimeSpan.Zero : GetKeyFrameTime(KeyFrames[index - 1], duration); TimeSpan segmentEnd = GetKeyFrameTime(KeyFrames[index], duration); double progress = segmentEnd == segmentStart ? 1 : (double)(time - segmentStart).Ticks / (segmentEnd - segmentStart).Ticks; value = KeyFrames[index].InterpolateValue(baseValue, progress); } if (IsAdditive && isAccumulable) { value = animationOperations.Add(value, (double?)defaultOriginValue); } if (IsCumulative && isAccumulable) { value = animationOperations.Add(value, animationOperations.Scale(KeyFrames[KeyFrames.Count - 1].Value, Math.Floor(animationClock.CurrentState.Iteration))); } return(value); }
private void SetGlowAnimation() { if (Indicator == null || glow == null || Indicator.ActualWidth.IsClose(currentAnimatedIndicatorWidth)) { return; } currentAnimatedIndicatorWidth = Indicator.ActualWidth; double currentOffset = glow.Margin.Left; if (currentAnimationClock != null) { ((IAnimatable)glow).RootClock.RemoveClock(currentAnimationClock); currentAnimationClock = null; } if (Indicator.ActualWidth > 0) { double startOffset = -glow.ActualWidth; double endOffset = Indicator.ActualWidth; TimeSpan time = TimeSpan.FromSeconds((endOffset - startOffset) / 200); ThicknessAnimationUsingKeyFrames thicknessAnimation = new ThicknessAnimationUsingKeyFrames(); thicknessAnimation.KeyFrames.Add(new LinearThicknessKeyFrame { Value = new Thickness(startOffset, 0, 0, 0), KeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero) }); thicknessAnimation.KeyFrames.Add(new LinearThicknessKeyFrame { Value = new Thickness(endOffset, 0, 0, 0), KeyTime = KeyTime.FromTimeSpan(time) }); thicknessAnimation.Duration = new Duration(time + TimeSpan.FromSeconds(1)); thicknessAnimation.RepeatBehavior = RepeatBehavior.Forever; thicknessAnimation.BeginTime = -time.Scale((currentOffset - startOffset) / (endOffset - startOffset)); currentAnimationClock = (AnimationTimelineClock)thicknessAnimation.CreateClock(); glow.ApplyAnimationClock(FrameworkElement.MarginProperty, currentAnimationClock); currentAnimationClock.Begin(((IAnimatable)glow).RootClock); } else { glow.ClearAnimationClocks(FrameworkElement.MarginProperty); } }
public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationTimelineClock animationClock) { return animationClock.CurrentState.Progress; }
public static void ApplyAnimationClock(this IAnimatable animatable, DependencyProperty dependencyProperty, AnimationTimelineClock animationClock, HandoffBehavior handoffBehavior = HandoffBehavior.SnapshotAndReplace, object layerOwner = null) { IEnumerable <AnimationTimelineClock> animationClocks = animationClock != null ? new[] { animationClock } : new AnimationTimelineClock[0]; animatable.ApplyAnimationClocks(dependencyProperty, animationClocks, handoffBehavior, layerOwner); }
public static void ApplyAnimationClock(this IAnimatable animatable, DependencyProperty dependencyProperty, AnimationTimelineClock animationClock, HandoffBehavior handoffBehavior = HandoffBehavior.SnapshotAndReplace, object layerOwner = null) { IEnumerable<AnimationTimelineClock> animationClocks = animationClock != null ? new[] { animationClock } : new AnimationTimelineClock[0]; animatable.ApplyAnimationClocks(dependencyProperty, animationClocks, handoffBehavior, layerOwner); }
private TargetKey GetClockTarget(AnimationTimelineClock clock, FrameworkElement containingObject, INameScope nameScope) { DependencyObject root = GetTarget(clock.Timeline); if (root == null) { string targetName = GetTargetName(clock.Timeline); if (targetName.IsNullOrEmpty()) { root = containingObject; } else { root = nameScope.FindName(targetName) as DependencyObject; if (root == null) { throw new Granular.Exception("Can't find Storyboard.TargetName \"{0}\" for element \"{1}\"", targetName, containingObject); } } } PropertyPath propertyPath = GetTargetProperty(clock.Timeline); DependencyObject target; DependencyProperty targetProperty; return TryGetPropertyPathTarget(root, propertyPath, out target, out targetProperty) && target is IAnimatable ? new TargetKey((IAnimatable)target, targetProperty) : null; }
public abstract object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationTimelineClock animationClock);