-api-id | -api-type |
---|---|
P:Windows.UI.Composition.Interactions.InteractionTracker.PositionVelocityInPixelsPerSecond |
winrt property |
The velocity currently applied to position.
The PositionVelocityInPixelsPerSecond property represents the current position velocity of InteractionTracker while in Inertia. There are two main use cases for this property: Retrieving the position velocity of InteractionTracker right after an interaction has occurred or reference the most current velocity of InteractionTracker in an ExpressionAnimation.
The velocity currently applied to position.
When accessing the PositionVelocityInPixelsPerSecond property from the InertiaStateEntered event, you will be retrieving a snapshot of the calculated velocity based on the interaction. This event will only fire once after the interaction has occurred.
// Listen for the InertiaStateEntered event, so we can grab PositionVelocityInPixelsPerSecond value.
public void InertiaStateEntered(InteractionTracker sender, InteractionTrackerInertiaStateEnteredArgs args)
{
// Grab the current velocity of InteractionTracker after interaction occurs out of the args when the event is fired.
Vector3 interactionVelocity = args.PositionVelocityInPixelsPerSecond;}
}
void CustomSpringMotion(float springCoefficient, float dampingCoefficient, float maxPosition)
{
// Create the InertiaModifier that will be a custom motion emulating a spring
InteractionTrackerInertiaMotion modifier = InteractionTrackerInertiaMotion.Create(_compositor);
modifier.Condition = _compositor.CreateExpressionAnimation("this.Target.NaturalRestingPosition.X > maxPosition");
modifier.Condition.SetScalarParameter("maxPosition", maxPosition);
// Utilize the current Velocity of InteractionTracker in the Expression defining the custom spring motion
modifier.Motion = _compositor.CreateExpressionAnimation("(-springStiffnessCoefficient * (this.Target.Position.X – maxPosition)) + (-dampingCoefficient * this.target.PositionVelocityInPixelsPerSecond.X");
modifier.Motion.SetScalarParameter("springStiffnessCoefficient", springCoefficient);
modifier.Motion.SetScalarParameter("dampingCoefficient", dampingCoefficient);
modifier.Motion.SetScalarParameter("maxPosition", maxPosition);
}