放大时我无法拖动?

时间:2014-11-15 03:05:31

标签: c# windows-phone-8 windows-phone-8.1 image-zoom

进入Copystransform,如果我在行尾删除了2,那么我可以放大和缩小但在放大时无法拖动。 还有什么我没有删除然后无法缩放,无法拖动。它只是在图片很小的情况下缩放,如果图片是全屏的则不是那样。

链接:http://blogs.msdn.com/b/wsdevsol/archive/2014/06/10/constraining-manipulations.aspx

double mincale = 0.5;
    //double maxscale = 10.0;
    CompositeTransform savedtransform = new CompositeTransform();
    private void Image_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
    {
       // FrameworkElement elemt = sender as FrameworkElement;
        Image elemt = sender as Image;
        CompositeTransform transform = elemt.RenderTransform as CompositeTransform;


        //
        copytransform(transform,savedtransform);

        //apply

        transform.ScaleX *= e.Delta.Scale;
        transform.ScaleY *= e.Delta.Scale;

        transform.TranslateX += e.Delta.Translation.X;
        transform.TranslateY += e.Delta.Translation.Y;

        if (transform.ScaleX < mincale) transform.ScaleX = mincale;
        if (transform.ScaleY < mincale) transform.ScaleY = mincale;
       // if (transform.ScaleX > maxscale) transform.ScaleX = maxscale;
       // if (transform.ScaleY > maxscale) transform.ScaleY = maxscale;
        if(elemt!=null)
        {


            if(!intersetElemnets(elemt,this.content,true))
            {
                copytransform(savedtransform, transform);
            }
        }



        /*
        double scalewidth = Zoomimages.ActualWidth * ct.ScaleX;
        double scleheight = Zoomimages.ActualHeight * ct.ScaleY;

        double xdiff = Math.Max(0, (scalewidth - this.content.ActualWidth) / 2);
        double ydiff = Math.Max(0, (scleheight - this.content.ActualHeight) / 2);

        if (Math.Abs(ct.TranslateX) > xdiff)
            ct.TranslateX = xdiff * Math.Sign(e.Delta.Translation.X);
        if (Math.Abs(ct.TranslateY) > ydiff)
            ct.TranslateY = ydiff * Math.Sign(e.Delta.Translation.Y);
         * */
    }
    private bool intersetElemnets(FrameworkElement inner, FrameworkElement outer,bool contains)
    {
        GeneralTransform testTransform = inner.TransformToVisual(outer);
        //
        Rect boundsinner = new Rect(0,0,inner.ActualWidth,inner.ActualHeight);
        Rect bboxouter = new Rect(0, 0, outer.ActualWidth, outer.ActualHeight);
        Rect bboxinner = testTransform.TransformBounds(boundsinner);

        if(contains)
        {
            return bboxinner.X > bboxouter.Y &&
                bboxinner.Y > bboxouter.Y &&
                bboxinner.Right < bboxouter.Right &&
                bboxinner.Bottom < bboxouter.Bottom;
        }
        else
        {
            bboxouter.Intersect(bboxinner);
            return !bboxouter.IsEmpty;
        }
    }
    private void copytransform(CompositeTransform orig,CompositeTransform copy)
    {
        copy.TranslateX = orig.TranslateX;
        copy.TranslateY = orig.TranslateY;
        copy.ScaleX = orig.ScaleX;
        copy.ScaleY = orig.ScaleY;
    }

0 个答案:

没有答案