在WPF中,我有一個網格,其中包含一段內容,我需要使用兩根手指觸摸手勢來操縱它。下面的代碼適用於移動和縮放,但我需要知道如何限制最大和最小縮放值,例如100%到200%縮放。此外,我需要限制內容的移動,以便它保持在網格容器的大小內。限制操作接受兩個手指觸摸
代碼到目前爲止:
私人小組gridLeft_ManipulationStarting(發送者爲對象,例如作爲ManipulationStartingEventArgs)把手gridLeft.ManipulationStarting
e.ManipulationContainer = gridMapHolderLeft
e.Mode = ManipulationModes.Scale + ManipulationModes.Translate
e.Handled = True
MyBase.OnManipulationStarting(e)
結束子
私人小組gridLeft_ManipulationDelta(發送者爲對象,例如As ManipulationDeltaEventArgs)句柄gridLeft.ManipulationDelta
Dim element As UIElement = TryCast(e.Source, UIElement)
Dim xform As MatrixTransform = TryCast(element.RenderTransform, MatrixTransform)
Dim matrix As Matrix = xform.Matrix
Dim delta As ManipulationDelta = e.DeltaManipulation
Dim center As Point = e.ManipulationOrigin
matrix.Translate(-center.X, -center.Y)
matrix.Scale(delta.Scale.X, delta.Scale.Y)
matrix.Translate(center.X, center.Y)
matrix.Translate(delta.Translation.X, delta.Translation.Y)
xform.Matrix = matrix
e.Handled = True
MyBase.OnManipulationDelta(e)
End Sub
非常感謝Olitee,這真的很有幫助 – ShedSpotter 2014-12-02 14:19:29