ViewportControl捏缩放中心

JTI*_*TIM 8 c# zoom viewport mvvm windows-phone-8

Hej我正在玩一个使用MVVM的Windows Phone 8应用程序.

我有一个问题,即获取捏缩放的中心并完全理解视口控制器上的边界.最后重新配置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>
Run Code Online (Sandbox Code Playgroud)

据我所知,Bounds是我想要滚动的区域,而高度和宽度是控件的窗口尺寸是正确的吗?

回答是的,这是正确的.

到第二部分:)获取捏缩放运动的中心.

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;
    }
Run Code Online (Sandbox Code Playgroud)

在if if if(!isZooming)的情况下,我尝试计算中心.我也尝试过在事件e中可以找到的不同中心.没有任何成功.我在计算中心时做错了什么?

最后,在我放大后,我再也无法平移整个画面了.因此,我需要更改一些变量,但在调试或搜索网络时无法确定它.有什么想法吗?

解答应调整图像大小,并且视口的边界应设置为已调整大小的图像的新大小.

编辑 最终问题是找到中心,问题出在这种情况发生时: 在此输入图像描述 因为e.PinchManipulation.Current给出了相对于浅蓝色方块,我希望它相对于大方块,即边界.这该怎么做?

Jon*_*N89 3

为了解决这个问题,我会做以下事情。视口控制器内部有一个滚动查看器和视口。

基本原理是这样的:

虽然您拥有的图像是“未缩放”的,但滚动查看器具有完全控制权,而 ViewportControl 不执行任何操作。当您开始捏合时,通过禁用垂直滚动条并设置 viewport.height =scrollviewer.height 来锁定滚动查看器。这会中和浏览器。您可以使用 Image ScaleTransform 进行临时缩放。捏合完成后,调整实际图像的大小,使其占据 ViewportControl 内的实际空间。现在,您的 viewportControl 将允许您平移整个缩放图像,并具有良好的反弹效果。当您再次缩小时,重新启用滚动查看器。(将高度设置为屏幕高度并打开滚动条。)仅供参考,我完全忘记了为什么那里有画布,但我觉得它很重要。见下文:

虽然下面的示例没有执行您想要执行的操作,但我基于此示例中的 MediaViewer 的代码并对其进行了修改:基本镜头示例

但需要注意的是,它是用于图片缩放。