Hej我正在玩使用MVVM的Windows Phone 8应用程序。ViewportControl捏缩放中心
我有一个问题,即获取缩放缩放的中心并完全理解视口控制器上的边界。最后重新配置viewportcontroller以继续滚动整个图片。我的XAML代码是:
<Grid>
<StackPanel>
<ViewportControl Bounds="0,0,1271,1381.5" Height="480" Width="800" CacheMode="BitmapCache" RenderTransformOrigin="{Binding KontaktPunkter}" Canvas.ZIndex="1">
<ViewportControl.RenderTransform>
<CompositeTransform x:Name="myTransform" ScaleX="1" ScaleY="1" TranslateX="0" TranslateY="0" />
</ViewportControl.RenderTransform>
<View:Picture/>
</ViewportControl>
</StackPanel>
<View:PopUpUC DataContext="{Binding PopUp}"/>
</Grid>
据我了解边界是我希望能够滚动区域,高度和宽度控制的窗口尺寸是否正确呢?
答案是的,它是正确的。
转到第二部分:)获取缩放变焦动作的中心。
public void ZoomDelta(ManipulationDeltaEventArgs e)
{
FrameworkElement Element = (FrameworkElement)e.OriginalSource;
ViewportControl Picture;
Grid PictureGrid;
double MainWidth = Application.Current.RootVisual.RenderSize.Height;
double MainHeight = Application.Current.RootVisual.RenderSize.Width;
if (Element is ViewportControl)
{
Picture = Element as ViewportControl;
}
else
{
Picture = FindParentOfType<ViewportControl>(Element);
}
if (Element is Grid)
{
PictueGrid = Element as Grid;
}
else
{
PictureGrid = FindParentOfType<Grid>(Element);
}
Grid ScreenGrid = FindParentOfType<Grid>(PictureGrid);
if (e.PinchManipulation != null)
{
var newScale = e.PinchManipulation.DeltaScale * Map.previousScale;
if (!IsZooming)
{
Point FingerOne = e.PinchManipulation.Current.PrimaryContact;
Point FingerTwo = e.PinchManipulation.Current.SecondaryContact;
Point center = new Point((FingerOne.X + FingerTwo.X)/2, (FingerOne.Y + FingerTwo.Y)/2);
KontaktPunkter = new Point(center.X/Picture.Bounds.Width, center.Y/Picture.Bounds.Height);
IsZooming = true;
}
var newscale = Map.imageScale * newScale;
var transform = (CompositeTransform)Picture.RenderTransform;
if (newscale > 1)
{
Map.imageScale *= newScale;
transform.ScaleX = Map.imageScale;
transform.ScaleY = Map.imageScale;
}
else
{
transform.ScaleX = transform.ScaleY = 1;
}
}
e.Handled = true;
}
在if情况下,如果(!isZooming),我尝试计算中心。我还尝试了可在事件e中找到的不同中心。没有任何成功。我在计算中心时做错了什么?
最后,我放大后,我无法泛过整个图片了。因此,我需要更改一些变量,但无法在调试或搜索网页时指定它。任何想法?
答案应调整图像大小,并将视口的边界设置为调整大小的图像的新大小。
编辑 最后一个问题是找到中心和问题,当这种情况发生时: 因为e.PinchManipulation.Current给出相对lightblue广场,我希望它相对于大型广场,即边界。这个怎么做?