Windows Phone 7 Image Controller: Zoom In, Zoom Out, and Rotate (WP 7 图像控制器:放大,缩小,旋转)
第一步: 下载 Silverlight for Windows Phone Toolkit - Nov 2010 安装的时候要暂时关闭VS (Visual Studio), 安装完后,打开VS,添加参考(Add References): Microsoft.Phone.Controls.Toolkit
第二步: 在WP 7 XAML文件中添加xmlns references:
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
第三步: 在XAML文件中设定image属性
<Image x:Name ="image1" RenderTransformOrigin="0.5, 0.5" CacheMode="BitmapCache" Height="662" Width="480">
<Image.RenderTransform>
<CompositeTransform x:Name="transform" />
</Image.RenderTransform>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener PinchStarted="OnPinchStarted" PinchDelta="OnPinchDelta" DragDelta="Postcard_ManipulationDelta"/>
</toolkit:GestureService.GestureListener>
</Image>
第四步:在CS文件中编写相关的Event Handler:
//Pinch Event Hanlder, including rotation, scale
private void OnPinchStarted(object sender, PinchStartedGestureEventArgs e)
{
initialAngle = transform.Rotation;
initialScale = transform.ScaleX;
}
private void OnPinchDelta(object sender, PinchGestureEventArgs e)
{
transform.Rotation = initialAngle + e.TotalAngleDelta;
transform.ScaleX = initialScale * e.DistanceRatio;
transform.ScaleY = initialScale * e.DistanceRatio;
}
private void Postcard_ManipulationDelta(object sender, DragDeltaGestureEventArgs e)
{
//moving along X axis
transform.TranslateX += e.HorizontalChange;
//moving along Y axis
transform.TranslateY += e.VerticalChange;
}
}
}
搞定,我也是刚接触WP 7 编程,欢迎大家一起讨论学习。