UIElement.ManipulationDelta Zdarzenie

Definicja

Występuje, gdy urządzenie wejściowe zmienia położenie podczas manipulowania.

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) 

Typ zdarzenia

Przykłady

W poniższym przykładzie przedstawiono procedurę obsługi zdarzeń dla ManipulationDelta zdarzenia. W przykładzie użyto DeltaManipulation właściwości do przenoszenia, zmieniania rozmiaru i obracania elementu Rectangle. Przykład sprawdza również, czy ManipulationDelta zdarzenie wystąpiło podczas inercji i czy prostokąt dotyka krawędzi okna. Jeśli te przypadki są prawdziwe, aplikacja zatrzymuje manipulację, aby uniemożliwić pozostawienie widocznego obszaru aplikacji. Ten przykład jest częścią większego przykładu w przewodniku: tworzenie pierwszej aplikacji dotykowej.

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

Uwagi

Zdarzenie ManipulationDelta występuje wielokrotnie, gdy użytkownik przeciąga palce na ekran podczas manipulowania i ponownie, gdy wystąpi inercja. Możesz użyć właściwości , IsInertial aby sprawdzić, czy zdarzenie występuje podczas inercji.

Element w ManipulationDelta przypadku wystąpienia zdarzenia nie ma wpływu w żaden sposób, gdy wystąpi zdarzenie. Należy podać logikę elementowi, który ma być manipulowany. Właściwości CumulativeManipulation i DeltaManipulation , które są typu ManipulationDelta, zawierają dane dotyczące zmiany położenia manipulacji i interpretowane jako przenoszenie, zmienianie rozmiaru lub obracanie obiektu. Te informacje są stosowane do elementu, który ma być manipulowany.

Aby uzyskać więcej informacji na temat manipulacji, zobacz Omówienie danych wejściowych. Przykład aplikacji, która reaguje na manipulacje, zobacz Przewodnik: tworzenie pierwszej aplikacji dotykowej.

Informacje dotyczące kierowanego zdarzenia

Pole identyfikatora ManipulationDeltaEvent
Strategia routingu Propagacji
Delegat EventHandler<TEventArgs> typu ManipulationDeltaEventArgs.

Dotyczy