Reputation: 1298
I want to make a Touch-Viewer where I want to zoom into the point between my finger.
I have a viewbox with content-presenter inside a grid:
<Grid IsManipulationEnabled="True">
<Viewbox x:Name="PART_Viewbox">
/// Content
</Viewbox>
</Grid>
Zoom in with the scrollwheel of my mouse into the point where the mouse is, i solved within the following methods:
var position = e.GetPosition(PART_Viewbox);
matrix.ScaleAtPrepend(scale, scale, position.X, position.Y);
The method e.GetPosition ist only available in MouseEventsArgs and not in ManipulationDeltaEventArgs.
So how can i get the relative position in touch-mode?
When i take the e.ManipulationOrigin from ManipulationDeltaEventArgs and the grid is bigger then the Viewbox it translates the content of the viewbox somewhere else while zooming in or out.
The most examples showing zooming into the middle of the content (image). Thats not what I want.
Upvotes: 0
Views: 1403
Reputation: 1298
The class FrameworkElement derives from UIElement. There is a method TranslatePoint which translates a point relative to a element.
In ManipulationDeltaEventArgs is a Property ManipulationOrigin which represents the point between the two fingers in a pinch zoom. An other important property is the ManipulationContainer that contains the element on that the manipulation is executed.
So in my case i can do following:
// Typecast ManipulationContainer to FrameworkElement and get point around the finger
Point position =((FrameworkElement)e.ManipulationContainer)
.TranslatePoint(e.ManipulationOrigin, _Viewbox);
// Center the new point in account to previous manipulations
position = matrix.Transform(position);
// do the transformation
matrix.ScaleAt(deltaManipulation.Scale.X, deltaManipulation.Scale.Y, position.X, position.Y)
I found this hint in the sourcecode of https://multitouchtransformbehavior.codeplex.com/
Upvotes: 1