metro c#–simple transform using touch
Well, this turned out to be pretty easy
……
The aim was to carry out a simple image transform with touch; so pinch zoom, translate and rotate. This is how the code turned out.
First, the xaml, which is an Image inside a Canvas…
<Image x:Name="myImage"
ManipulationMode="All"
ManipulationDelta="Image_ManipulationDelta_1"
RenderTransformOrigin="0.5, 0.5">
<Image.RenderTransform>
<CompositeTransform></CompositeTransform>
</Image.RenderTransform>
</Image>
</Canvas>
Then the event handler for the ManipulationDelta event
{
var ct = (CompositeTransform)myImage.RenderTransform;
ct.ScaleX *= e.Delta.Scale;
ct.ScaleY *= e.Delta.Scale;
ct.TranslateX += e.Delta.Translation.X;
ct.TranslateY += e.Delta.Translation.Y;
ct.Rotation += 180.0 / Math.PI * e.Delta.Rotation;
UpdateControls(ct);
}
And here’s the sample running on my Build slate…
The code is available here…
Comments