ManipulationDeltaEventArgs Class

Definition

Provides data for the ManipulationDelta event.

public sealed class ManipulationDeltaEventArgs : System.Windows.Input.InputEventArgs
Inheritance

Examples

The following example shows an event handler for the ManipulationDelta event. The example uses the DeltaManipulation property to move, resize, and rotate a Rectangle. 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

Remarks

The ManipulationDeltaEventArgs class contains data about changes in the position of a manipulation. The DeltaManipulation property contains the changes that occurred since the last ManipulationDelta event occurred. The CumulativeManipulation property contains the total changes that occurred for the current manipulation. You use one of those properties to transform the manipulated object.

You can end a manipulation by calling the Complete method or force the manipulation into inertia by calling the StartInertia method.

Properties

CumulativeManipulation

Gets the cumulated changes of the current manipulation.

DeltaManipulation

Gets the most recent changes of the current manipulation.

Device Inherited from InputEventArgs
Handled Inherited from RoutedEventArgs
IsInertial

Gets a value that indicates whether the ManipulationDelta event occurs during inertia.

ManipulationContainer

Gets the container that defines the coordinates for the manipulation.

ManipulationOrigin

Gets the point from which the manipulation originated.

Manipulators

Gets a collection of objects that represents the touch contacts for the manipulation.

OriginalSource Inherited from RoutedEventArgs
RoutedEvent Inherited from RoutedEventArgs
Source Inherited from RoutedEventArgs
Timestamp Inherited from InputEventArgs
Velocities

Gets the rates of the most recent changes to the manipulation.

Methods

Cancel()

Cancels the manipulation.

Complete()

Completes the manipulation without inertia.

Equals(Object) Inherited from Object
Equals(Object, Object) Inherited from Object
GetHashCode() Inherited from Object
GetType() Inherited from Object
InvokeEventHandler(Delegate, Object) Inherited from InputEventArgs
MemberwiseClone() Inherited from Object
OnSetSource(Object) Inherited from RoutedEventArgs
ReferenceEquals(Object, Object) Inherited from Object
ReportBoundaryFeedback(ManipulationDelta)

Specifies that the manipulation has gone beyond certain boundaries.

StartInertia()

Starts inertia on the manipulation by ignoring subsequent contact movements and raising the ManipulationInertiaStarting event.

ToString() Inherited from Object

Fields

Empty Inherited from EventArgs

Applies to