C# 我能';放大时不要拖动?
到Copystransform,如果我删除了行末尾的2,那么我可以放大和缩小,但不能在放大的同时拖动。 还有什么我没有删除,然后不能缩放和拖动。它只是在图片很小的时候进行缩放,否则如果图片是全屏的话就不会这样了 链接:C# 我能';放大时不要拖动?,c#,windows-phone-8,windows-phone-8.1,zooming,C#,Windows Phone 8,Windows Phone 8.1,Zooming,到Copystransform,如果我删除了行末尾的2,那么我可以放大和缩小,但不能在放大的同时拖动。 还有什么我没有删除,然后不能缩放和拖动。它只是在图片很小的时候进行缩放,否则如果图片是全屏的话就不会这样了 链接: double mincale=0.5; //双最大刻度=10.0; CompositeTransform savedtransform=新CompositeTransform(); 私有void Image_操纵delta(对象发送方,操纵deltaroutedventargs
double mincale=0.5;
//双最大刻度=10.0;
CompositeTransform savedtransform=新CompositeTransform();
私有void Image_操纵delta(对象发送方,操纵deltaroutedventargs e)
{
//frameworkelemt=发送方作为FrameworkElement;
Image elemt=发送方作为图像;
CompositeTransform transform=elemt.RenderTransform作为CompositeTransform;
//
copytransform(transform,savedtransform);
//申请
transform.ScaleX*=e.Delta.Scale;
transform.ScaleY*=e.Delta.Scale;
transform.TranslateX+=e.Delta.Translation.X;
transform.TranslateY+=e.Delta.translate.Y;
如果(transform.ScaleXmaxscale)transform.ScaleX=maxscale;
//如果(transform.ScaleY>maxscale)transform.ScaleY=maxscale;
if(elemt!=null)
{
if(!nets(elemt,this.content,true))
{
copytransform(savedtransform,transform);
}
}
/*
双刻度宽度=Zoomimages.ActualWidth*ct.ScaleX;
双螺旋高度=缩放图像。实际高度*ct。比例;
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*数学符号(e.Delta.TranslateX.X);
if(数学Abs(ct.TranslateY)>ydiff)
ct.TranslateY=ydiff*数学符号(e.Delta.translate.Y);
* */
}
私有bool网络(FrameworkElement内部、FrameworkElement外部、bool包含)
{
GeneralTransform testTransform=内部.TransformToVisual(外部);
//
Rect boundsinner=新的Rect(0,0,内部.ActualWidth,内部.ActualHeight);
Rect bboxouter=新的Rect(0,0,outer.ActualWidth,outer.ActualHeight);
Rect bboxiner=testTransform.TransformBounds(bounder);
如果(包含)
{
返回bboxiner.X>bboxouter.Y&&
bboxiner.Y>bboxouter.Y&&
bboxiner.Right
您需要下载整个源代码。你错过了Rob代码中的XAML部分…这就是为什么它让你如此困惑的原因。我试过了,但没有成功。
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;
}