2010-01-21 49 views
4

我正在使用.NET 4 beta 2觸摸庫,並試圖在我的WPF應用程序中實現縮放功能。WPF 4觸摸事件獲取捏手勢的中心

我可以使縮放工作得很好,但我想要的是放大縮小手勢的中心,並且我看不到有關如何完成此操作的API中的任何內容。

是否有一些方法或屬性,暴露在捏手勢中使用的2個聯繫人,以便我可以得到他們的中心?

編輯:

我只是用的TouchEventArgsGetIntermediateTouchPoints方法,它似乎並沒有給我我想要什麼樣的影響。

非常感謝 馬克

回答

0

原來我以前的屬性一直在我的面前。

Manipulation2DDeltaEventArgs類有OriginXOriginX性質特定縮放手勢的中心點,所以我只是使用其所有好的:)

0

假設你正在使用的新TouchXxxxEvent路由事件,他們都採取TouchEventArgs,其中有TouchDevice財產。如果您撥打GetTouchPoint()方法,則可以獲取代表觸摸點的TouchPoint

更多details and sample code來自Jaime Rodriguez。

+0

我使用此刻的'TouchDown'事件,但使用'ManipulationDelta'的實際操縱林。我可以看到'GetIntermediateTouchPoints'方法,這可能是在這裏後im ... – Mark

+0

不是那種方法似乎沒有做我想做的事情,所以現在我可能不得不跟蹤接觸,然後計算兩者之間的距離他們...難看! – Mark

0

這個答案是對.NET 4的發佈版本。

在使用ManipulationDelta事件的情況下,ManipulationDeltaEventArgs.ManipulationOrigin包含捏手勢的中心點。座標是相對於ManipulationDeltaEventArgs.ManipulationContainer,可以在ManipulationStarting事件的處理程序中設置。

示例代碼:

private void object_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) 
{ 
    ... 
    // If this was a multitouch gesture 
    // (like pinch/zoom - indicated by e.DeltaManipulation.Scale) 
    // the following line will get us point between fingers. 
    Point position = e.ManipulationOrigin; 
    ... 
}