2013-01-08 38 views
1

我正在爲PixelSense2.0開發Sur40應用程序。我試圖捕捉觸摸輸入,但它一直給我提供相同的錯誤:No overload for method 'GetTouchPoint' takes 0 arguments方法'GetTouchPoint'沒有重載需要0個參數

這是我到目前爲止的代碼:

void SurfaceWindow1_Loaded(object sender, RoutedEventArgs e) 
    { 


     this.TouchDown += new EventHandler<TouchEventArgs>(SurfaceWindow1_TouchDown); 

    } 

    void SurfaceWindow1_TouchDown(object sender, TouchEventArgs e) 
    { 
     LoadAnimationControl2 ani1 = new LoadAnimationControl2(); 
     ani1.Margin.Left = e.GetTouchPoint().Position.X; 
     ani1.Margin.Bottom = e.GetTouchPoint().Position.Y; 
     MainGrid.Children.Add(ani1); 
    } 

沒有任何人有一個建議如何處理這個問題呢?

回答

1
void SurfaceWindow1_TouchDown(object sender, TouchEventArgs e) 
{ 
    LoadAnimationControl2 ani1 = new LoadAnimationControl2(); 
    ani1.Margin.Left = e.GetTouchPoint(this).Position.X; 
    ani1.Margin.Bottom = e.GetTouchPoint(this).Position.Y; 
    MainGrid.Children.Add(ani1); 
} 
+0

此代碼對我幫助很大,但它崩潰上ani1.Margin出現錯誤:它因爲...不是變量不能修改「System.Windows.FrameworkElement.Margin」的返回值。我如何解決這個問題? –

+0

@NielsVerhoeven我快速瀏覽了文檔,看起來您只需將其設置爲厚度'btn1.Margin = new Thickness(60);'參考:http://msdn.microsoft.com/en-us /library/system.windows.frameworkelement.margin.aspx – jac

+0

感謝您的幫助!它現在正在工作! –

2

那麼根據docs

public TouchPoint GetTouchPoint(
    IInputElement relativeTo 
) 

它需要一個IInputElement是:The element that defines the coordinate space.
並返回:The current position of the touch device relative to the specified element.

所以,你需要做的是通過在你的「屏幕」或任何正確的術語是獲得正在觀看的內容。

相關問題