UIElement.ManipulationDelta 事件

定義

輸入裝置在操作期間變更位置時發生。

C#
public event EventHandler<System.Windows.Input.ManipulationDeltaEventArgs> ManipulationDelta;

事件類型

範例

下列範例顯示 事件的事件處理常式 ManipulationDelta 。 此範例會 DeltaManipulation 使用 屬性來移動、調整大小及旋轉 Rectangle 。 此範例也會檢查 ManipulationDelta 是否在慣性期間發生事件,以及矩形是否觸碰視窗邊緣。 如果這些情況成立,應用程式會停止操作,以防止矩形離開應用程式的可見區域。 此範例是逐步解 說:建立您的第一個觸控應用程式中較大範例的一部分。

C#
void Window_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
    
    // Get the Rectangle and its RenderTransform matrix.
    Rectangle rectToMove = e.OriginalSource as Rectangle;
    Matrix rectsMatrix = ((MatrixTransform)rectToMove.RenderTransform).Matrix;

    // Rotate the Rectangle.
    rectsMatrix.RotateAt(e.DeltaManipulation.Rotation, 
                         e.ManipulationOrigin.X, 
                         e.ManipulationOrigin.Y);

    // Resize the Rectangle.  Keep it square 
    // so use only the X value of Scale.
    rectsMatrix.ScaleAt(e.DeltaManipulation.Scale.X, 
                        e.DeltaManipulation.Scale.X, 
                        e.ManipulationOrigin.X,
                        e.ManipulationOrigin.Y);

    // Move the Rectangle.
    rectsMatrix.Translate(e.DeltaManipulation.Translation.X,
                          e.DeltaManipulation.Translation.Y);

    // Apply the changes to the Rectangle.
    rectToMove.RenderTransform = new MatrixTransform(rectsMatrix);

    Rect containingRect =
        new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);

    Rect shapeBounds =
        rectToMove.RenderTransform.TransformBounds(
            new Rect(rectToMove.RenderSize));

    // Check if the rectangle is completely in the window.
    // If it is not and intertia is occuring, stop the manipulation.
    if (e.IsInertial && !containingRect.Contains(shapeBounds))
    {
        e.Complete();
    }

    e.Handled = true;
}

備註

當使用者 ManipulationDelta 在操作期間將手指拖曳到螢幕上,並在發生慣性時再次發生時,就會多次發生此事件。 您可以使用 IsInertial 屬性來檢查事件是否在慣性期間發生。

當事件發生時,發生 事件 ManipulationDelta 上的 專案不會以任何方式受到影響。 您必須將邏輯提供給要操作的專案。 CumulativeManipulationDeltaManipulation 屬性屬於 類型 ManipulationDelta ,包含操作位置如何變更及解譯為移動、調整大小或旋轉物件的資料。 您可以將該資訊套用至要操作的專案。

如需操作的詳細資訊,請參閱 輸入概觀。 如需回應操作的應用程式範例,請參閱逐步解說 :建立您的第一個觸控應用程式

路由事件資訊

識別碼欄位 ManipulationDeltaEvent
路由策略 鼓 泡
代理人 型別 EventHandler<TEventArgs>ManipulationDeltaEventArgs

適用於

產品 版本
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9