2014-11-08 106 views
0

我有一個大約4048x8096的畫布,當我嘗試放大時,它沒有放大手勢點,它總是移動到Point(0,0),這是畫布的位置,這裏是我正在使用的代碼: 當達到縮放限制時,它也會閃爍。放大觸摸點

private void GraphSurface_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e) 
{ 
    var matrix = ((MatrixTransform)this.RenderTransform).Matrix; 

    Point center = new Point(this.ActualWidth/2, this.ActualHeight/2); 

    center = matrix.Transform(center); 

     if (Scale <= ZoomInLimit && Scale >= ZoomOutLimit) 
     { 
      matrix.ScaleAt(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.Y, center.X, center.Y); 
     } 

     if (Scale > ZoomInLimit) 
     { 
      matrix.M11 -= 0.001; 
      matrix.M22 -= 0.001; 
     } 
     else if (Scale < ZoomOutLimit) 
     { 
      matrix.M11 = ZoomOutLimit + 0.001; 
      matrix.M22 = ZoomOutLimit + 0.001; 
     } 

    ((MatrixTransform)this.RenderTransform).Matrix = matrix; 

    e.Handled = true; 
} 
+0

看看[如何自動中心在ScrollViewer中同時縮放內容](http://www.xaml.in/xaml/how-to-auto-center-the-content-in- a-scrollviewer-zooming)幫助。 – pushpraj 2014-11-09 00:41:25

回答

0

這是一個在手勢點放大的演示。使用底部的例子。代碼是JS,而不是Java,但它應該轉換好。將awesome_tiger.svg替換爲您的畫布對象。也許這會給你一個你自己的代碼需要的樣本。希望有所幫助。

http://timmywil.github.io/jquery.panzoom/demo/