如果!我现在在多点触控的时候,放大缩小实现了,但放大后拖动图片,会将图片拖出屏幕,这是我做的一个DEMO, 地址如下:https://onedrive.live.com/redir?resid=56C8C9A332A136A7!287&authkey=!AL5pu2Nvxx66dGc&ithint=file%2c.rar可以下载此demo下来看下,在此demo基础下修改,或者有现成的控制例子也可以,实在是想不到方法解决了!
试过了System.Windows.Application.Current.Host.Content来获取屏幕可显示区域,但还是没能实现完全控制,这一部分代码如下,private void GestureListener_DragCompleted(object sender, DragCompletedGestureEventArgs e) { double dtransformX = (double)CurrentImage.RenderTransform.GetValue(CompositeTransform.TranslateXProperty); double dtransformY = (double)CurrentImage.RenderTransform.GetValue(CompositeTransform.TranslateYProperty);
double dWidth = System.Windows.Application.Current.Host.Content.ActualWidth; double dHeight = System.Windows.Application.Current.Host.Content.ActualHeight; double dPositionX = e.GetPosition(CurrentImage).X; //CurrentImage为当前界面显示图片的image对象 double dPositionY = e.GetPosition(CurrentImage).Y;
if (Math.Abs(dPositionX) > dWidth / 2) dtransformX = 0.0; //如果移动的距离大于屏幕的一半,就不移动
if (Math.Abs(dPositionY) > dHeight / 2) dtransformY = 0.0;
CompositeTransform cc = new CompositeTransform(); cc.TranslateX = dtransformX; cc.TranslateY = dtransformY; cc.SetValue(CompositeTransform.ScaleXProperty, CurrentImage.RenderTransform.GetValue(CompositeTransform.ScaleXProperty)); cc.SetValue(CompositeTransform.ScaleYProperty, CurrentImage.RenderTransform.GetValue(CompositeTransform.ScaleYProperty)); cc.SetValue(CompositeTransform.CenterXProperty, CurrentImage.RenderTransform.GetValue(CompositeTransform.CenterXProperty)); cc.SetValue(CompositeTransform.CenterYProperty, CurrentImage.RenderTransform.GetValue(CompositeTransform.CenterYProperty)); CurrentImage.SetValue(RenderTransformProperty, cc);