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. 如果这些事例为 true, 则应用程序将停止操作以防止矩形离开应用程序的可见区域。If those cases are true, the application stops the manipulation to prevent the rectangle from leaving the visible area of the application. 本示例是演练中更大示例的一部分:正在创建您的第一个 Touch 应用程序。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. 有关响应操作的应用程序的示例, 请参阅演练:正在创建您的第一个 Touch 应用程序。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 EventHandler<TEventArgs>类型ManipulationDeltaEventArgsEventHandler<TEventArgs> of type ManipulationDeltaEventArgs.

适用于