WPF 4 touch events getting the center of a pinch gesture

☆樱花仙子☆ 提交于 2020-01-03 15:34:47

问题


I am using the .net 4 beta 2 touch libraries, and Im trying to implement a zooming feature in my WPF application.

I can get the zooming working just fine, but what I want is to zoom in on the center of the pinch gesture, and I cannot see anything in the API's about how to accomplish this.

Is there some methods or properties that expose the 2 contacts being using in the pinch gesture so that I can get the center of them?

EDIT:

I just investigated using the GetIntermediateTouchPoints method of TouchEventArgs which did not seem to give me what I want.

Thanks a lot Mark


回答1:


Assuming you are using the new TouchXxxxEvent routed events, they all take TouchEventArgs, which has TouchDevice property. If you call its GetTouchPoint() method, you can get the TouchPoint that represents the point of touch.

More details and sample code from Jaime Rodriguez.




回答2:


Turns out that the properties I was after was right in front of me all along.

the Manipulation2DDeltaEventArgs class has OriginX and OriginX properties that specific the center point of the pinch gesture, so Im just using that and its all good :)




回答3:


This answer is for .Net 4 release version.

In the case of using ManipulationDelta event the ManipulationDeltaEventArgs.ManipulationOrigin contains center point of the pinch gesture. The coordinates are relative to the ManipulationDeltaEventArgs.ManipulationContainer, which could be set in the handler of ManipulationStarting event.

Example code:

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;
    ...
}


来源:https://stackoverflow.com/questions/2108353/wpf-4-touch-events-getting-the-center-of-a-pinch-gesture

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!