private void page_Loaded(object sender, RoutedEventArgs e) { Loaded -= page_Loaded; spVisual = ElementCompositionPreview.GetElementVisual(spContent); btnScrollVisual = ElementCompositionPreview.GetElementVisual(btn_Scroll); compositor = spVisual.Compositor; tracker = InteractionTracker.Create(compositor); var tref = tracker.GetReference(); var trackerTarget = ExpressionValues.Target.CreateInteractionTrackerTarget(); var endpoint1 = InteractionTrackerInertiaRestingValue.Create(compositor); endpoint1.SetCondition(trackerTarget.NaturalRestingPosition.Y < (trackerTarget.MaxPosition.Y - trackerTarget.MinPosition.Y) / 2); endpoint1.SetRestingValue(trackerTarget.MinPosition.Y); var endpoint2 = InteractionTrackerInertiaRestingValue.Create(compositor); endpoint2.SetCondition(trackerTarget.NaturalRestingPosition.Y >= (trackerTarget.MaxPosition.Y - trackerTarget.MinPosition.Y) / 2); endpoint2.SetRestingValue(trackerTarget.MaxPosition.Y); tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { endpoint1, endpoint2 }); interactionSource = VisualInteractionSource.Create(spVisual); interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; tracker.InteractionSources.Add(interactionSource); propertySet = compositor.CreatePropertySet(); propertySet.InsertScalar("progress", 0.0f); propertySet.StartAnimation("progress", tref.Position.Y / tref.MaxPosition.Y); var progress = propertySet.GetReference().GetScalarProperty("progress"); btnScrollVisual.StartAnimation("RotationAngleInDegrees", ExpressionFunctions.Clamp(progress, 0f, 1f) * 180); btnScrollVisual.CenterPoint = new System.Numerics.Vector3((float)btn_Scroll.ActualWidth / 2, (float)btn_Scroll.ActualHeight / 2, 0); spVisual.StartAnimation("Offset.Y", -ExpressionFunctions.Clamp(progress, -0.4f, 1.4f) * tref.MaxPosition.Y); gdInfo_SizeChanged(this, null); }
private void SetupInteractionTracker() { // Setup the HitTest visual of the InteractionTracker. _hitTestVisual = VisualExtensions.GetVisual(Card); _hitTestVisual.Size = Card.RenderSize.ToVector2(); // TODO: Why this doesn't work? //_hitTestVisual.RelativeSizeAdjustment = Vector2.One; // In this sample, we only want interactions happening on the Y-axis. _interactionSource = VisualInteractionSource.Create(_hitTestVisual); _interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; _tracker.InteractionSources.Add(_interactionSource); // Setup max position of the InteractionTracker. var distanceFromTop = (float)Card.RelativePosition(this).Y; _maxDistance = distanceFromTop + _hitTestVisual.Size.Y; _tracker.MaxPosition = new Vector3(_maxDistance); // Initialize the manipulation progress. // Note: In this simple demo, we could have used the trackerNode.Position.Y to manipulate the offset // directly. But we use the manipulation progress here so we could control more things such as the // scale or opacity of the "copy" in the future. _progress.InsertScalar("Progress", 0); // Create an animation that tracks the progress of the manipulation and stores it in a the PropertySet _progress. var trackerNode = _tracker.GetReference(); // Note here we don't want to EF.Clamp the value 'cause we want the overpan which gives a more natural feel // when you pan it. _progress.StartAnimation("Progress", trackerNode.Position.Y / _tracker.MaxPosition.Y); ConfigureRestingPoints(); void ConfigureRestingPoints() { // Setup a possible inertia endpoint (snap point) for the InteractionTracker's minimum position. var endpoint1 = InteractionTrackerInertiaRestingValue.Create(_compositor); // Use this endpoint when the natural resting position of the interaction is less than the halfway point. var trackerTarget = ExpressionValues.Target.CreateInteractionTrackerTarget(); endpoint1.SetCondition(trackerTarget.NaturalRestingPosition.Y < (trackerTarget.MaxPosition.Y - trackerTarget.MinPosition.Y) / 2); // Set the result for this condition to make the InteractionTracker's y position the minimum y position. endpoint1.SetRestingValue(trackerTarget.MinPosition.Y); // Setup a possible inertia endpoint (snap point) for the InteractionTracker's maximum position. var endpoint2 = InteractionTrackerInertiaRestingValue.Create(_compositor); // Use this endpoint when the natural resting position of the interaction is more than the halfway point. endpoint2.SetCondition(trackerTarget.NaturalRestingPosition.Y >= (trackerTarget.MaxPosition.Y - trackerTarget.MinPosition.Y) / 2); // Set the result for this condition to make the InteractionTracker's y position the maximum y position. endpoint2.SetRestingValue(trackerTarget.MaxPosition.Y); _tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { endpoint1, endpoint2 }); } }
private void ActivateSpringForce() { var dampingConstant = 5; var springConstant = 20; var modifier = InteractionTrackerInertiaMotion.Create(_compositor); // Set the condition to true (always) modifier.SetCondition((BooleanNode)true); // Define a spring-like force, anchored at position 0. var target = ExpressionValues.Target.CreateInteractionTrackerTarget(); modifier.SetMotion((-target.Position.Y * springConstant) - (dampingConstant * target.PositionVelocityInPixelsPerSecond.Y)); _tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { modifier }); }
private void ActivateSpringForce(float pullToRefreshDistance) { var dampingConstant = 5; var springConstant = 5; var modifier = InteractionTrackerInertiaMotion.Create(_compositor); // Set the condition to true (always) modifier.SetCondition((BooleanNode)true); var target = ExpressionValues.Target.CreateInteractionTrackerTarget(); // Define a spring-like force, anchored at position 0. This brings the listView back to position 0. modifier.SetMotion(-(target.Position.Y * springConstant) - (target.PositionVelocityInPixelsPerSecond.Y * dampingConstant)); _tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { modifier }); }
private void ActivateSpringForce() { var dampingConstant = 5; var springConstant = 20; var modifier = InteractionTrackerInertiaMotion.Create(_compositor); // Set the condition to true (always) modifier.Condition = _compositor.CreateExpressionAnimation("true"); // Define a spring-like force, anchored at position 0. modifier.Motion = _compositor.CreateExpressionAnimation(@"(-(this.target.Position.Y) * springConstant) - (dampingConstant * this.target.PositionVelocityInPixelsPerSecond.Y)"); modifier.Motion.SetScalarParameter("dampingConstant", dampingConstant); modifier.Motion.SetScalarParameter("springConstant", springConstant); _tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { modifier }); }
private void SetupRestingPoints() { var endpoint1 = InteractionTrackerInertiaRestingValue.Create(_compositor); endpoint1.Condition = _compositor.CreateExpressionAnimation("this.target.NaturalRestingPosition.y < (this.target.MaxPosition.y - this.target.MinPosition.y) /2"); endpoint1.RestingValue = _compositor.CreateExpressionAnimation("this.target.MinPosition.y"); var endpoint2 = InteractionTrackerInertiaRestingValue.Create(_compositor); endpoint2.Condition = _compositor.CreateExpressionAnimation("this.target.NaturalRestingPosition.y >= (this.target.MaxPosition.y - this.target.MinPosition.y) /2"); endpoint2.RestingValue = _compositor.CreateExpressionAnimation("this.target.MaxPosition.y"); _tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { endpoint1, endpoint2 }); }
private void ActivateSpringForce() { #if SDKVERSION_15063 // // On newer builds, use the Spring NaturalMotion // if (MainPage.RuntimeCapabilities.IsSdkVersionRuntimeSupported(RuntimeSupportedSDKs.SDKVERSION._15063)) { var modifier = InteractionTrackerInertiaNaturalMotion.Create(_compositor); var springAnimation = _compositor.CreateSpringScalarAnimation(); springAnimation.Period = TimeSpan.FromSeconds(.15); springAnimation.DampingRatio = .4f; springAnimation.FinalValue = 0.0f; modifier.Condition = _compositor.CreateExpressionAnimation("true"); modifier.NaturalMotion = springAnimation; _tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { modifier }); } // // On older builds, use a custom force that behaves like a spring // else #endif { var dampingConstant = 5; var springConstant = 20; var modifier = InteractionTrackerInertiaMotion.Create(_compositor); // Set the condition to true (always) modifier.SetCondition((BooleanNode)true); // Define a spring-like force, anchored at position 0. var target = ExpressionValues.Target.CreateInteractionTrackerTarget(); modifier.SetMotion((-target.Position.Y * springConstant) - (dampingConstant * target.PositionVelocityInPixelsPerSecond.Y)); _tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { modifier }); } }
private void InitializeSnapAnimationModifiers() { var trackerNode = _tracker.GetReference(); ScalarNode closedPosition = 0; var snapClosed = InteractionTrackerInertiaRestingValue.Create(_compositor); snapClosed.SetCondition(trackerNode.NaturalRestingPosition.Y < openSize / 2); snapClosed.SetRestingValue(closedPosition); var snapOpen = InteractionTrackerInertiaRestingValue.Create(_compositor); snapOpen.SetCondition(trackerNode.NaturalRestingPosition.Y < openSize * 1.5f); snapOpen.SetRestingValue((ScalarNode)openSize); var modifiers = new InteractionTrackerInertiaRestingValue[] { snapClosed, snapOpen }; _tracker.ConfigurePositionYInertiaModifiers(modifiers); }