-api-id | -api-type |
---|---|
M:Microsoft.UI.Composition.Interactions.InteractionTracker.TryUpdatePosition(Windows.Foundation.Numerics.Vector3) |
winrt method |
Tries to update the InteractionTracker's position.
The TryUpdatePosition method updates the location of InteractionTracker to the Vector3 position specified as a parameter. TryUpdatePosition is used to declaratively define the position of InteractionTracker at any point in time (either at start, from some state-entered event, etc.). TryUpdatePosition can be called from either the Idle, CustomAnimation or Inertia state – doing so will move the position of InteractionTracker to the defined position and enter the idle state.
The new position for the InteractionTracker.
Returns the request ID. On state transitions, the request which caused the change in state will be included in the args. These IDs will start at 1 and increase with each try call during the lifetime of the application.
If InteractionTracker is in its Interacting State (user actively manipulating), and TryUpdatePosition is called, the system will ignore this request – an event gets fired when this occurs that can be listened for. If sent from one of the other states, listen for the event fired for IdleStateEntered and check the RequestId property that identifies which request triggered the callback. The table below summarizes the expected behavior when this method is called in a particular state:
Current State | Outcome |
---|---|
Idle | Property updates to requested value, no state changes |
Interacting | Request ignored |
Inertia | Property updates to requested value, state changes to Idle |
CustomAnimation | Property updates to requested value, state changes to Idle |
void SetupInteractionTracker()
{
// Setup InteractionTracker
_tracker = InteractionTracker.Create(_compositor);
_interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia;
_interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;
_tracker.InteractionSources.Add(_interactionSource);
_tracker.PositionInertiaDecayRate = new Vector3(0.95f);
// Update the position of InteractionTracker, so doesn’t start at (0,0)
_tracker.TryUpdatePosition(new Vector3(50f));
}