The ManipulationMode
should be set on the Img
control instead. Also, you probably want to specify the exact modes you want rather than All
to prevent unnecessary gesture handling.
<Image x:Name="Img" Source="{x:Bind ImgSource}" Width="150" Height="150" Stretch="UniformToFill"
ManipulationMode="TranslateX, TranslateY"
ManipulationStarted="Img_ManipulationStarted"
ManipulationDelta="Img_ManipulationDelta"
ManipulationCompleted="Img_ManipulationCompleted">
<Image.RenderTransform>
<CompositeTransform x:Name="Transform" />
</Image.RenderTransform>
</Image>
From your description above, I think turning on both TranslateX
and TranslateY
should be sufficient. Then you will need to handle manipulation events like ManipulationStarted
, ManipulationDelta
and ManipulationCompleted
.
Most of your logic should be done in ManipulationDelta
event which will be fired multiple times during the progression of the panning. It's where you get the X
and Y
positions and set them accordingly.
Here is a simple sample for this.
void Img_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
// dim the image while panning
this.Img.Opacity = 0.4;
}
void Img_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
this.Transform.TranslateX += e.Delta.Translation.X;
this.Transform.TranslateY += e.Delta.Translation.Y;
}
void Img_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
// reset the Opacity
this.Img.Opacity = 1;
}