private void CompositionTarget_Rendering(object sender, EventArgs e) { if (AssociatedObject == null || !AssociatedObject.IsVisible) { return; } if (currentInteractionStatus == InteractionStatus.PreEngaged) { PreEngagementAnimationHelper.Update(); } if (currentInteractionStatus != InteractionStatus.Scrolling) { return; } UpdateSnapAnimation(); if (CurrentForce <= 0 && (Convert.ToInt32(AssociatedObject.ScrollPosition % MaximumDegreeReturnSnap) == 0) && isSnapAnimationCompleted) { currentInteractionStatus = InteractionStatus.None; return; } var currentTime = DateTime.Now; var elapsedTime = currentTime - LastUpdate; CurrentVelocity = CurrentForce / BodyMass; var dueDisplacement = CurrentVelocity * (Double)elapsedTime.TotalMilliseconds; if (CurrentForceDirection == ForceDirection.Down) { dueDisplacement *= -1; } var newOffset = AssociatedObject.ScrollPosition + dueDisplacement; if (Double.IsNaN(newOffset)) { return; } AssociatedObject.ScrollPosition = newOffset; CurrentForce = Math.Max(0, CurrentForce - ((Double)elapsedTime.TotalMilliseconds * CurrentForce * Friction)); if (CurrentForce < 0.0001) { CurrentForce = 0; } if (!isSnapAnimationCompleted) { return; } if (CurrentVelocity <= SnapVelocity) { var roundedOffset = Math.Round(newOffset, 0); var goalOffset = GetSnapOffset(roundedOffset); CurrentForce = 0; StartSnapAnimation(AssociatedObject.ScrollPosition, goalOffset); } LastUpdate = DateTime.Now; }
private void UpdateSnapAnimation() { SnapAnimationHelper.Update(); }