UIElement.ManipulationDelta UIElement.ManipulationDelta UIElement.ManipulationDelta UIElement.ManipulationDelta Event

定義

輸入裝置在操作期間變更位置時發生。Occurs when the input device changes position during a manipulation.

public:
 event EventHandler<System::Windows::Input::ManipulationDeltaEventArgs ^> ^ ManipulationDelta;
public event EventHandler<System.Windows.Input.ManipulationDeltaEventArgs> ManipulationDelta;
member this.ManipulationDelta : EventHandler<System.Windows.Input.ManipulationDeltaEventArgs> 
Public Custom Event ManipulationDelta As EventHandler(Of ManipulationDeltaEventArgs) 

範例

下列範例會顯示ManipulationDelta事件的事件處理常式。The following example shows an event handler for the ManipulationDelta event. 這個範例會使用DeltaManipulation屬性來移動、調整大小和Rectangle旋轉。The example uses the DeltaManipulation property to move, resize, and rotate a Rectangle. 此範例也會檢查ManipulationDelta事件是否發生在慣性期間, 以及矩形是否觸及視窗的邊緣。The example also checks whether the ManipulationDelta event occurred during inertia and whether the rectangle is touching the edge of a window. 如果這些情況成立, 應用程式會停止操作, 防止矩形離開應用程式的可見區域。If those cases are true, the application stops the manipulation to prevent the rectangle from leaving the visible area of the application. 這個範例是逐步解說中較大範例的一部分:建立您的第一個觸控應用程式。This example is part of a larger example in Walkthrough: Creating Your First Touch Application.

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;
}
Private Sub Window_ManipulationDelta(ByVal sender As Object, ByVal e As ManipulationDeltaEventArgs)

    ' Get the Rectangle and its RenderTransform matrix.
    Dim rectToMove As Rectangle = e.OriginalSource
    Dim rectTransform As MatrixTransform = rectToMove.RenderTransform
    Dim rectsMatrix As Matrix = rectTransform.Matrix


    ' Rotate the shape
    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 center
    rectsMatrix.Translate(e.DeltaManipulation.Translation.X,
                          e.DeltaManipulation.Translation.Y)

    ' Apply the changes to the Rectangle.
    rectTransform = New MatrixTransform(rectsMatrix)
    rectToMove.RenderTransform = rectTransform

    Dim container As FrameworkElement = e.ManipulationContainer
    Dim containingRect As New Rect(container.RenderSize)

    Dim shapeBounds As Rect = rectTransform.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 AndAlso Not containingRect.Contains(shapeBounds) Then
        e.Complete()
    End If

    e.Handled = True
End Sub

備註

ManipulationDelta使用者在操作期間將手指拖曳到螢幕上, 並在發生慣性時再次執行時, 就會發生此事件多次。The ManipulationDelta event occurs multiple times when the user drags fingers over the screen during a manipulation and again when inertia occurs. 您可以使用IsInertial屬性來檢查事件是否發生在慣性期間。You can use the IsInertial property to check whether the event is occurring during inertia.

發生事件時, ManipulationDelta不會以任何方式影響具有事件的元素。The element on with ManipulationDelta event occurs is not affected in any way when the event occurs. 您必須將邏輯提供給要操作的元素。You must provide the logic to the element that is to be manipulated. 和屬性 (屬於類型ManipulationDelta) 包含操作位置如何變更, 以及如何將其轉譯為移動、調整大小或旋轉物件的相關資料。 DeltaManipulation CumulativeManipulationThe CumulativeManipulation and DeltaManipulation properties, which are of type ManipulationDelta, contain data about how the position of the manipulations change and interpreted as moving, resizing, or rotating an object. 您會將該資訊套用至要操作的元素。You apply that information to the element that is to be manipulated.

如需操作的詳細資訊, 請參閱輸入總覽For more information about manipulations, see the Input Overview. 如需回應操作的應用程式範例, 請參閱逐步解說:建立您的第一個觸控應用程式。For an example of an application that responds to manipulations, see Walkthrough: Creating Your First Touch Application.

路由事件資訊Routed Event Information

識別碼欄位Identifier field ManipulationDeltaEvent
路由策略Routing strategy 路由Bubbling
Delegate - 委派Delegate 型別 EventHandler<TEventArgs>ManipulationDeltaEventArgsEventHandler<TEventArgs> of type ManipulationDeltaEventArgs.

適用於