Windows 8 touch language features a simple set of gestures such as tap for primary action, slide to pan or drag an object, and swipe for selection. The touch experience should always be consistent and responsive. Despite the simplicity and flexibility of the Windows 8 touch programming model, there still are a couple of important performance best practices for you to learn.
|API surface||CSS Properties||DOM Attributes||DOM Events|
For the best scrolling and zooming performance, use CSS properties. (For more info about the CSS properties and guidelines for using them, see Touch input.)
When you set these CSS properties, the platform optimizes performance and resource allocation by using separate threads to handle the touch input. You might not benefit from this optimization when you handle the
MSPointer or MSGesture events manually.
A pointer object represents a single, unique input contact (a PointerPoint) from an input device (such as a mouse, pen/stylus, a finger, or multiple fingers). In the case of multiple devices or multi-touch input, each contact is treated as a unique pointer. In Windows 8, this pointer data is handled through a unified input stack for mouse, pen/stylus, and touch devices. Use the pointer object to code for touch and get mouse and pen input for free. If you want to customize the user experience for a specific device, you can use device-specific properties to write code that device. The DOM pointer events follow the familiar pattern of DOM mouse events, with extensions for touch properties and interaction principles.
The basic DOM pointer events include mspointerdown, mspointermove, and mspointerup. You can also use MSGesture events to easily access the touch language. The DOM performs gesture recognition, and raises gesture events that you can handle with your code. Here are some of the events you can register for:
|DOM gesture event examples|
|Static gesture events|
|Manipulation gesture events|
A static gesture event triggers a specific action through touch interactions such as tap, double tap, press and tap, and hold gestures. You can use these gestures as a substitute for mouse events that involve similar actions. The user performs a specific predefined interaction that triggers a gesture, and after the interaction is completed, the system raises a gesture event.
The manipulation gesture events indicate an ongoing user interaction. The system raises manipulation gesture events when the user touches the element. The system continues to raise manipulation gesture events until the user lifts the finger from the manipulated element .
Choose static or manipulation gesture events based on your app's needs, but also consider their performance impact. If your app needs to provide a quick, custom response immediately when the user touches an element, handle the mspointerdown event or the related manipulation gesture event.
Don't animate your UI in time with input events. For example, if you're creating a paint app, don't draw to the canvas each time an mspointermove event is raised because it will degrade the app's performance.
To get smooth animations and rendering, an app needs to render only at 30 frames per second (fps), which is the speed most monitors can render at. But most input events happen quicker than 30 fps (touch events can happen more than 100 times a second). If you render along with an input event, you're forcing the app to do more work than necessary.
Build date: 11/16/2013