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

拥有回忆 提交于 2019-12-12 20:10:56

问题


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


回答1:


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

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


来源:https://stackoverflow.com/questions/20004620/manipulationdelta-only-translation-has-values-scale-and-rotation-is-always-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!