private void SetAnimationClocks( IList <AnimationClock> animationClocks) { Debug.Assert(animationClocks != null); Debug.Assert(animationClocks.Count > 0); Debug.Assert(!animationClocks.Contains(null)); Debug.Assert(_animationClocks == null); _animationClocks = animationClocks; int count = animationClocks.Count; for (int i = 0; i < count; i++) { _ownerStorage.AttachAnimationClock(animationClocks[i], _removeRequestedHandler); } }
[FriendAccessAllowed] // Built into Core, also used by Framework. internal static void ApplyAnimationClocks( DependencyObject d, DependencyProperty dp, IList <AnimationClock> animationClocks, HandoffBehavior handoffBehavior) { Debug.Assert(animationClocks != null, "The animationClocks parameter should not be passed in as null."); Debug.Assert(animationClocks.Count > 0, "The animationClocks parameter should contain at least one clock."); Debug.Assert(!animationClocks.Contains(null), "The animationClocks parameter should not contain a null entry."); Debug.Assert(HandoffBehaviorEnum.IsDefined(handoffBehavior), "Public API caller of this internal method is responsible for validating that the HandoffBehavior value is valid."); AnimationStorage storage = GetStorage(d, dp); // handoffBehavior is SnapshotAndReplace or the situation is such // that it is the equivalent because we have nothing to compose // with. if (handoffBehavior == HandoffBehavior.SnapshotAndReplace || storage == null || storage._animationClocks == null) { if (storage != null) { EventHandler handler = new EventHandler(storage.OnCurrentStateInvalidated); // If we have a sticky snapshot value, the clock that would have // unstuck it is being replaced, so we need to remove our event // handler from that clock. if (storage._hasStickySnapshotValue) { storage._animationClocks[0].CurrentStateInvalidated -= handler; } // Calculate a snapshot value if we don't already have one // since the last tick. else { storage._snapshotValue = d.GetValue(dp); } // If we have a new clock in a stopped state, then the snapshot // value will be sticky. if (animationClocks[0].CurrentState == ClockState.Stopped) { storage._hasStickySnapshotValue = true; animationClocks[0].CurrentStateInvalidated += new EventHandler(storage.OnCurrentStateInvalidated); } // Otherwise it won't be sticky. else { storage._hasStickySnapshotValue = false; } storage.ClearAnimations(); } else { storage = CreateStorage(d, dp); } // Add and attach new animation. storage._animationClocks = new FrugalObjectList <AnimationClock>(animationClocks.Count); for (int i = 0; i < animationClocks.Count; i++) { Debug.Assert(animationClocks[i] != null); storage._animationClocks.Add(animationClocks[i]); storage.AttachAnimationClock(animationClocks[i], storage._removeRequestedHandler); } } else { Debug.Assert(handoffBehavior == HandoffBehavior.Compose); Debug.Assert(storage != null); Debug.Assert(storage._animationClocks != null); FrugalObjectList <AnimationClock> newClockCollection = new FrugalObjectList <AnimationClock>(storage._animationClocks.Count + animationClocks.Count); for (int i = 0; i < storage._animationClocks.Count; i++) { newClockCollection.Add(storage._animationClocks[i]); } storage._animationClocks = newClockCollection; for (int i = 0; i < animationClocks.Count; i++) { newClockCollection.Add(animationClocks[i]); storage.AttachAnimationClock(animationClocks[i], storage._removeRequestedHandler); } } storage.WritePostscript(); }