ManipulationDelta - 只有翻译具有价值,缩放和旋转始终是“身份” [英] ManipulationDelta - Only Translation has values, Scale and Rotation is always 'Identity'
问题描述
我尝试实现了多点触控的用户界面(在棕地项目)的<一个href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.manipulationdelta%28v=vs.110%29.aspx"相对=nofollow> ManipulationDelta事件 WPF的。但是我只得到了平移值,而从来不是规模或旋转。
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.
我的测试code是这样的:
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...
谢谢! 斯特凡
推荐答案
您必须调用<一个href="http://msdn.microsoft.com/en-us/library/system.windows.input.manipulation.setmanipulationmode.aspx"相对=nofollow> Manipulation.SetManipulationMode
在在ManipulationStarted
事件处理程序:
You have to call Manipulation.SetManipulationMode
in a ManipulationStarted
event handler:
private void ScrollViewerViewModelManipulationStarted(
object sender, ManipulationStartedEventArgs e)
{
Manipulation.SetManipulationMode((UIElement)sender, ManipulationModes.All);
}
这篇关于ManipulationDelta - 只有翻译具有价值,缩放和旋转始终是“身份”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!