Share via


UIElement.ManipulationDelta Kejadian

Definisi

Terjadi ketika perangkat input berubah posisi selama manipulasi.

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) 

Jenis Acara

Contoh

Contoh berikut menunjukkan penanganan aktivitas untuk peristiwa tersebut ManipulationDelta . Contohnya menggunakan DeltaManipulation properti untuk memindahkan, mengubah ukuran, dan memutar Rectangle. Contohnya juga memeriksa apakah ManipulationDelta peristiwa terjadi selama inertia dan apakah persegi panjang menyentuh tepi jendela. Jika kasus tersebut benar, aplikasi menghentikan manipulasi untuk mencegah persegi panjang meninggalkan area aplikasi yang terlihat. Contoh ini adalah bagian dari contoh yang lebih besar di Walkthrough: Membuat Aplikasi Sentuhan Pertama Anda.

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

Keterangan

Peristiwa terjadi ManipulationDelta beberapa kali ketika pengguna menyeret jari di atas layar selama manipulasi dan lagi ketika inertia terjadi. Anda dapat menggunakan IsInertial properti untuk memeriksa apakah peristiwa terjadi selama inertia.

Elemen pada dengan ManipulationDelta peristiwa terjadi tidak terpengaruh dengan cara apa pun ketika peristiwa terjadi. Anda harus memberikan logika ke elemen yang akan dimanipulasi. Properti CumulativeManipulation dan DeltaManipulation , yang berjenis ManipulationDelta, berisi data tentang bagaimana posisi manipulasi berubah dan ditafsirkan sebagai memindahkan, mengubah ukuran, atau memutar objek. Anda menerapkan informasi tersebut ke elemen yang akan dimanipulasi.

Untuk informasi selengkapnya tentang manipulasi, lihat Gambaran Umum Input. Untuk contoh aplikasi yang merespons manipulasi, lihat Panduan: Membuat Aplikasi Sentuhan Pertama Anda.

Informasi Peristiwa Yang Dirutekan

Bidang pengidentifikasi ManipulationDeltaEvent
Strategi perutean Menggelegak
Delegasikan EventHandler<TEventArgs> jenis ManipulationDeltaEventArgs.

Berlaku untuk