如果你不希望使用深Z,你还可以使用ViewBox,以包含图像,并听取GisBox使用“Rendertransform”在和从该观点中流出的骨折射/偶和zo。
下面是我用于银灯的一些代码,其中某些工作可以改变,以对平方作出反应,而不是用 mo轮+点击/d。 也可能根据胎体的“体积”改变动物体积。
在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