VisualInteractionSource.TryRedirectForManipulation(PointerPoint) 方法

定義

指出指定指標資料流程的設定操作應該傳送至 InteractionTracker,而不是應用程式 UI 執行緒,從指定的 PointerPoint 開始。

TryRedirectForManipulation 可讓VisualInteractionSource在手勢符合VisualInteractionSource上的組態時,將指標資料流程重新導向至InteractionTracker。 這個方法應該只使用 DeviceType Touch 的指標輸入來呼叫。

public:
 virtual void TryRedirectForManipulation(PointerPoint ^ pointerPoint) = TryRedirectForManipulation;
void TryRedirectForManipulation(PointerPoint const& pointerPoint);
public void TryRedirectForManipulation(PointerPoint pointerPoint);
function tryRedirectForManipulation(pointerPoint)
Public Sub TryRedirectForManipulation (pointerPoint As PointerPoint)

參數

pointerPoint
PointerPoint

指出指定指標資料流程的設定操作應該傳送至 InteractionTracker,而不是應用程式 UI 執行緒,從指定的 PointerPoint 開始。

範例

///////////////////////////////////////////////////////////////////////////////////////////////
//
// The following sample describes how to configure a visual to follow input/gestures.  
//
// This is accomplished in three main steps:
//
// 1) Creating a InteractionTracker and setting (or binding) its boundaries.
//
// 2) Creating at least one Interaction source and associating it with the InteractionTracker.
//
// 3) Taking the output of the InteractionTracker and applying it to a Visual's Offset and Scale 
//    properties.
//
// 4) Telling the system to try to handle the manipulation when the PointerPressed occurs
//
///////////////////////////////////////////////////////////////////////////////////////////////

void SetupSimpleInteractionTracker(Visual containerVisual, Visual contentVisual)
{
  //
  // Create the InteractionTracker and set its min/max position and scale.  These could 
  // also be bound to expressions.  Note: The scrollable area can be changed from either 
  // end to facilitate content updates/virtualization.
  //

  _tracker = InteractionTracker.Create(_compositor);

  _tracker.MaxPosition = new Vector3(
  contentVisual.Size.X - containerVisual.Size.X,
  contentVisual.Size.Y - containerVisual.Size.Y,
  0.0f);

  _tracker.MinScale = 0.5f;
  _tracker.MaxScale = 4.0f;


  //
  // Configure the interaction source.  Enable input with inertia on all axes.
  //

  _interactionSource = VisualInteractionSource.Create(_compositor, containerVisual);

  _interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia;
  _interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;
  _interactionSource.ScaleSourceMode = InteractionSourceMode.EnabledWithInertia;

  _tracker.InteractionSources.Add(_interactionSource);

  //
  // Register for the pointer pressed event so that we can tell the system to handle the
  // manipulations.
  //

  _rootElement.PointerPressed += OnPointerPressedBasic;

  //
  // Bind the InteractionTracker outputs to the contentVisual.
  //

  var positionExpression = _compositor.CreateExpressionAnimation("-tracker.Position");
  positionExpression.SetReferenceParameter("tracker", _tracker);

  contentVisual.StartAnimation("Offset", positionExpression);


  var scaleExpression = _compositor.CreateExpressionAnimation("Vector3(tracker.Scale, tracker.Scale, 1.0)");

  scaleExpression.SetReferenceParameter("tracker", _tracker);

  contentVisual.StartAnimation("Scale", scaleExpression);
}

private void OnPointerPressedBasic(object sender, PointerRoutedEventArgs e)
{
  //
  // Try to handle the manipulation in the system.
  //
  if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch)
  {       
    _interactionSource.TryRedirectForManipulation(
    e.CurrentPoint.GetCurrentPoint(_rootElement));
  }
}

Compositor _compositor = null;
InteractionTracker _tracker = null;
UIElement _rootElement = null;
VisualInteractionSource _interactionSource;

備註

此方法可讓應用程式指出系統 (Compositor) 應該接管指定 VisualInteractionSource的任何已設定操作。 呼叫 TryRedirectForManipulation 時,來自傳入 PointerPoint 的框架會作為 InteractionTracker 輸入處理的起點。 如果使用者的手勢經過點擊測試至與 VisualInteractionSource 相關聯的視覺效果 (或其其中一個子系) ,且使用者會執行已設定的手勢,則系統會操作。 如果輸入已點擊測試到另一個視覺效果,或使用者執行未設定的手勢,則會將輸入傳送至 CoreWindow,並透過 XAML 的一般輸入路由傳送。

如果 VisualInteractionSource 會將輸入資料流程重新路由傳送至 InteractionTracker,應用程式將會在 UIElement 上收到 PointerCaptureLost,或 CoreWindow 上的 PointerRoutedAway。 這些訊息表示輸入已從應用程式 UI 執行緒傳送。 此方法最常在 PointerPressed 上呼叫。

PrecisionTouchpad 輸入不需要此呼叫,而且如果 InputRedirectionMode 已設定為包含 CapableTouchpad 輸入,則會自動路由傳送至 InteractionTracker

限制

非同步本質

這個系統的本質是非同步。 在應用程式呼叫 TryRedirectForManipulation 且呼叫到達撰寫器時,可能會有其他輸入事件已對應用程式的 UI 執行緒進行。 在大部分情況下,應用程式無法收到這些事件,而開發人員可以選擇手勢偵測應用程式端,以判斷如何處理輸入並減輕疑慮。 應用程式會知道系統操作是否透過接收 PointerCaptureLost 來接管,這是 ScrollViewer 目前接管輸入處理時所收到的相同事件。 此處的其中一個複雜在於,手勢就像「快速閃爍」, (只是一個簡短的移動流覽) ,將整個輸入資料流程,包括 PointerReleased 傳送給應用程式,然後撰寫器才能回應。 如果應用程式受到這些限制的影響,他們可以選擇在其端執行一些手勢偵測,以確保正確的行為。

與 XAML 控制項邏輯整合

在上述快速閃爍案例中,移動流覽發生于按鈕之類的控制項上,如果按鈕包含在按鈕內,按鈕會偵測移動流覽作為按一下。 這與執行路由) 偵測手勢的系統 GestureRecognizer (稍有不同。 為了確保快速閃爍類型案例能夠與 XAML 正確搭配運作,開發人員必須在按鈕上接聽 OnTapped,而不只是按一下它位於撰寫器互動區域中。

Compositor Hit-testing

用來判斷操作是否在右側視覺效果上發生的點擊測試結果,會根據撰寫器的點擊測試。 Compositor 點擊測試與 XAML 點擊測試不一樣強固,因此在某些情況下,結果可能會稍微不一致。

如需詳細資訊,請參閱 VisualInteractionSource檔。

與衝突的自訂手勢辨識器整合

在內部,系統會使用 GestureRecognizer 來路由輸入。 只要應用程式使用系統手勢辨識,應用程式通常會取得他們想要的行為。 如果應用程式嘗試使用與系統辨識器衝突的自訂辨識器,則應用程式預期組合器接管且不會發生衝突。

適用於