2013-07-30 84 views
1

如何通過拖動/捏住手指而不發生異常行爲來移動/調整SurfaceWindow本身的尺寸?我有一個表面窗口,檢查IsManipulationEnabled。在ManipulationStarting,我有:移動和調整表面窗口本身的尺寸

e.ManipulationContainer = this; <--- source of unpredictable behavior? 
    e.Handled = true; 

ManipulationDelta

this.Left += e.DeltaManipulation.Translation.X; 
    this.Top += e.DeltaManipulation.Translation.Y; 
    this.Width *= e.DeltaManipulation.Scale.X; <----zooming works properly 
    this.Height *= e.DeltaManipulation.Scale.X; 

    e.Handled = true; 

與移動的問題是,它會保持與兩個完全不同的位置跳來跳去,給它一個閃爍的效果。我在控制檯中輸出了一些數據,看起來e.ManipulationOrigin不斷變化。下面的數據是值後,我在最後在屏幕上(只印X值),然後拖動拿着我的手指下降固定爲第二:

Window.Left e.Manipulation.Origin.X e.DeltaManipulation.Translation.X 
--------------------------------------------------------------------------- 
1184   699.616     0 
1184   577.147     -122.468 
1062   577.147     0 
1062   699.264     122.117 
1184   699.264     0 
1184   576.913     -122.351 

and it goes on 

您可以從Window.Left看到它2之間跳躍位置。在我用手指停止移動窗口後,如何才能讓它保持靜止?

回答

0

下面的代碼至少可以讓你拖動;它通過使用屏幕座標解決了您遇到的問題 - 因爲使用窗口座標意味着參考點隨着窗口移動而改變。

http://www.codeproject.com/Questions/671379/How-to-drag-window-with-finger-not-mouse更多信息..

static void MakeDragging(Window window) { 
      bool isDown = false; 
      Point position = default(Point); 
      window.MouseDown += (sender, eventArgs) => { 
       if (eventArgs.LeftButton != MouseButtonState.Pressed) return; 
       isDown = true; 
       position = window.PointToScreen(eventArgs.GetPosition(window)); 
      }; 
      window.MouseUp += (sender, eventArgs) => { 
       if (eventArgs.LeftButton != MouseButtonState.Released) return; 
       isDown = false; 
      }; 
      window.MouseMove += (sender, eventArgs) => { 
       if (!isDown) return; 
       Point newPosition = window.PointToScreen(eventArgs.GetPosition(window)); 
       window.Left += newPosition.X - position.X; 
       window.Top += newPosition.Y - position.Y; 
       position = newPosition; 
      }; 
     } //MakeDragging 
+0

我不認爲用多個手指移動將與該正常工作 –

相關問題