我想在Windows Phone 7设备上显示更大的图像。我需要能够使用多点触控手势放大和缩小。我想知道是否有任何控件可以在Windows Phone 7 SDK中开箱即用?
答案 0 :(得分:6)
如果您不想使用DeepZoom,您还可以使用ViewBox来包含图像,并使用RenderTransform监听捏合触摸手势/事件并放大和缩小ViewBox。
下面是我用于Silverlight应用程序的一些代码,可以更改某些工作以对Pinch和触摸手势做出反应,而不是鼠标滚轮+单击/拖动事件。也可以根据捏合手势的“强度”来改变缩放量。
对于在XAML中定义的视图框:
<Border Name="viewboxBackground" Background="Black">
<Viewbox Name="viewboxMain">
<!--your content here -->
</Viewbox>
</Border>
代码隐藏:
#region Pan and Zoom Events and Handlers
void MouseClickHandler(object sender, MouseButtonEventArgs e)
{
_mouseClickPos = e.GetPosition(viewboxBackground);
bMoving = true;
}
void MouseMoveHandler(object sender, MouseEventArgs e)
{
if (bMoving)
{
//get current transform
CompositeTransform transform = viewboxMain.RenderTransform as CompositeTransform;
Point currentPos = e.GetPosition(viewboxBackground);
transform.TranslateX += (currentPos.X - _mouseClickPos.X);
transform.TranslateY += (currentPos.Y - _mouseClickPos.Y);
viewboxMain.RenderTransform = transform;
_mouseClickPos = currentPos;
}
}
void MouseReleaseHandler(object sender, MouseButtonEventArgs e)
{
bMoving = false;
}
void MouseWheelZoom(object sender, MouseWheelEventArgs e)
{
if (e.Delta > 0)
{
_zoomMultiplier += _zoomRate;
ApplyZoomTransform(viewboxMain, _zoomMultiplier, new Point(viewboxMain.ActualWidth / 2, viewboxMain.ActualHeight / 2));
}
else if (e.Delta < 0 && _zoomMultiplier > 1)
{
_zoomMultiplier -= _zoomRate;
ApplyZoomTransform(viewboxMain, _zoomMultiplier, new Point(viewboxMain.ActualWidth / 2, viewboxMain.ActualHeight / 2));
}
}
/// <summary>
///
/// </summary>
/// <param name="element"></param>
/// <param name="iZoomFactor"></param>
/// <param name="zoomCenter">If provided, the zoom will be centered around the given position.</param>
void ApplyZoomTransform(UIElement element, double iZoomFactor, Point? zoomCenter)
{
//get current transform
CompositeTransform transform = viewboxMain.RenderTransform as CompositeTransform;
if (zoomCenter != null)
{
transform.CenterX = zoomCenter.GetValueOrDefault().X;
transform.CenterY = zoomCenter.GetValueOrDefault().Y;
}
transform.ScaleX = iZoomFactor;
transform.ScaleY = iZoomFactor;
element.RenderTransform = transform;
}
#endregion
答案 1 :(得分:2)
您可能对DeepZoom感兴趣。不确定支持多点触控手势的效果如何,但如果多点触控支持不标准,您可以了解如何使用gestures here并模拟多点触控here。 以下是DeepZoom on WP7的示例视频。
答案 2 :(得分:1)
您可能还会发现Laurent Bugnion的多点触控行为值得一看。缩放图像。