habakuk
habakuk

Reputation: 2771

ManipulationDelta - Only Translation has values, Scale and Rotation is always 'Identity'

I try to implement a multi-touch ui (in a brownfield project) with the ManipulationDelta event of wpf. But I only get values for translation, but never for scale or rotation.

My test code looks like this:

        Private Sub ScrollViewerViewModelManipulationDelta(sender As Object, e As Input.ManipulationDeltaEventArgs) Handles Me.ManipulationDelta

        Dim transform As MatrixTransform = TryCast(RenderTransform, MatrixTransform)
        If transform Is Nothing Then transform = New MatrixTransform(RenderTransform.Value)
        Dim matrix As Matrix = transform.Matrix

        If e.DeltaManipulation.Scale.X <> 1 OrElse e.DeltaManipulation.Scale.Y <> 1 Then
            matrix.ScaleAt(e.DeltaManipulation.Scale.X,
                            e.DeltaManipulation.Scale.Y,
                            e.ManipulationOrigin.X,
                            e.ManipulationOrigin.Y)
        End If
        If e.DeltaManipulation.Translation.X <> 1 OrElse e.DeltaManipulation.Translation.Y <> 1 Then
            'matrix.Translate(e.DeltaManipulation.Translation.X,
            '                e.DeltaManipulation.Translation.Y)
        End If
        If e.DeltaManipulation.Rotation <> 0 Then
            matrix.RotateAt(e.DeltaManipulation.Rotation,
                 e.ManipulationOrigin.X,
                 e.ManipulationOrigin.Y)
        End If

        RenderTransform = New MatrixTransform(matrix)

        If e.IsInertial Then
            e.Complete()
        End If

        'e.Handled = True

    End Sub

Any idea what I'm missing here? I tried the gestures for zooming and rotating, but I only get translations...

Thanks! Stefan

Upvotes: 2

Views: 1118

Answers (1)

Clemens
Clemens

Reputation: 128181

You have to call Manipulation.SetManipulationMode in a ManipulationStartedevent handler:

private void ScrollViewerViewModelManipulationStarted(
    object sender, ManipulationStartedEventArgs e)
{
    Manipulation.SetManipulationMode((UIElement)sender, ManipulationModes.All);
}

Upvotes: 3

Related Questions