New WPF Features: MultiTouch

This is part of a series on New WPF Features  

WPF supports multitouch API’s in .NET 4. You can have touch and manipulation operations on all the UI elements.

For creating a touch based app, you would need to subscribe to the events:

· TouchDown

·  TouchEnter

·  TouchLeave

·  TouchMove

·  TouchUp

The TouchEventArgs class has some helpful API

· GetTouchPoint - Returns the current position of the touch device relative to the specified element.

· TouchDevice - Gets the device that generated the event.

· Device - Gets the input device that initiated this event. (Inherited from InputEventArgs.)

 

To add manipulations, you first need to set the bool IsManipulationEnabled property. Once done you can now listen to the manipulation events

· ManipulationStarted

· ManipulationDelta

· ManipulationStarting

· ManipulationCompleted

 

You can restrict the manipulations that are allowed by specifying the ManipulationMode in the Starting event.

Member name

Description

None

Manipulation events do not occur.

TranslateX

A manipulation can translate an object horizontally.

TranslateY

A manipulation can translate an object vertically.

Translate

A manipulation can translate an object.

Rotate

A manipulation can rotate an object.

Scale

A manipulation can scale an object

All (default)

A manipulation can scale, translate, or rotate an object and can occur with one point of input.

 

Next you listen to the delta in the manipulations and perform the necessary transform, rotation,…

The manipulationDeltaEventArgs provides the DeltaManipulation property that you can use for

Name

Description

Expansion

Gets or sets the amount the manipulation has resized in .

Rotation

Gets or sets the rotation of the manipulation in degrees.

Scale

Gets or sets the amount the manipulation has resized as a multiplier.

Translation

Gets or sets the linear motion of the manipulation.

 

A sample app demonstrating the usage can be found here

Touch design guidelines can be found here

 

Share this post