如何在Windows Phone 8中实现捏合缩放和多点触控功能。在我的应用程序中,我在网格中添加了3个图像容器,我需要在我的图像上执行上述操作。请任何人帮我实现我的应用程序中的功能。提前谢谢。
Stez
答案 0 :(得分:2)
答案 1 :(得分:1)
我的解决方案适用于WP7.5和WP8:
XAML代码
<StackPanel x:Name="Scroll" Margin="0">
<Image CacheMode="BitmapCache" Name="FrontCover" Source="{Binding FullCover}" >
<Image.RenderTransform>
<CompositeTransform x:Name="transform" ScaleX="1" ScaleY="1" />
</Image.RenderTransform>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener PinchDelta="OnPinchDelta" PinchStarted="OnPinchStarted" DragDelta="OnDragDelta" />
</toolkit:GestureService.GestureListener>
</Image>
</StackPanel>
double initialScale;
private void OnPinchStarted(object sender, PinchStartedGestureEventArgs e)
{
initialScale = transform.ScaleX;
}
private void OnPinchDelta(object sender, PinchGestureEventArgs e)
{
var curZoom = initialScale * e.DistanceRatio;
if (curZoom >= 1 && curZoom <= 3)
{
transform.ScaleX = curZoom;
transform.ScaleY = curZoom;
}
}
private void OnDragDelta(object sender, DragDeltaGestureEventArgs e)
{
transform.CenterX = (transform.CenterX - e.HorizontalChange);
transform.CenterY = (transform.CenterY - e.VerticalChange);
if (transform.CenterX < 0)
transform.CenterX = 0;
else if ( transform.CenterX > Scroll.ActualWidth)
transform.CenterX = Scroll.ActualWidth;
else if (transform.CenterX > (FrontCover.Height * transform.ScaleX))
transform.CenterX = FrontCover.Height * transform.ScaleX;
if (transform.CenterY < 0)
transform.CenterY = 0;
else if (transform.CenterY > Scroll.ActualHeight)
transform.CenterY = Scroll.ActualHeight;
else if (transform.CenterY > (FrontCover.Height * transform.ScaleY))
transform.CenterY = FrontCover.Height * transform.ScaleY;
}
认为它应该帮助别人