C#wpf使用delta操作执行缩放,转换变换

时间:2015-09-20 11:22:39

标签: c# wpf

我正在尝试在椭圆上执行缩放和平移变换,这是我的代码:

void ellipse_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
   {

       Ellipse rp = (Ellipse)sender;
       if (e.PinchManipulation != null)
       {
           ((CompositeTransform)rp.RenderTransform).ScaleX *= e.DeltaManipulation.Scale.X;
           ((CompositeTransform)rp.RenderTransform).ScaleY *= e.DeltaManipulation.Scale.X;

       }

       ((CompositeTransform)rp.RenderTransform).TranslateX += e.DeltaManipulation.Translation.X;
       ((CompositeTransform)rp.RenderTransform).TranslateY += e.DeltaManipulation.Translation.Y;
   }

代码工作正常,但问题是,在执行缩放转换后,转换不能完美地工作,它要么减速要么跳跃,我认为这是因为夹点操作中心位置的变化。我该如何避免?有什么建议吗?

1 个答案:

答案 0 :(得分:0)

这是你想要做的那种操纵的example。根据我在该示例中看到的内容,您的问题是您没有设置缩放转换的中心点。

从链接到示例/演练:

Point center = new Point(this.BasicRect.RenderSize.Width / 2.0, this.BasicRect.RenderSize.Height / 2.0);
this.scale.CenterX = center.X;
this.scale.CenterY = center.Y;
this.scale.ScaleX *= e.DeltaManipulation.Scale.X;
this.scale.ScaleY *= e.DeltaManipulation.Scale.Y;