问题
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 ManipulationStarted
event 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