PointerEventArgs infrastructure used for mouse input, but with touch-specific features like multi-touch support.
Touch Device
TheTouchDevice class handles raw touch events on a per-toplevel basis. It manages multiple simultaneous touch points and dispatches them as pointer events.
Key Features
- Multi-touch Support: Each touch contact is represented by a unique
IPointerinstance - Automatic Capture: Touch contacts are automatically captured to the element they first touch
- Double-Tap Detection: Built-in support for detecting double-tap gestures
- Gesture Recognition: Integrates with gesture recognizers for pinch, scroll, and pull gestures
Touch Event Lifecycle
Touch events follow this lifecycle:- TouchBegin →
PointerPressedevent - TouchUpdate →
PointerMovedevent - TouchEnd →
PointerReleasedevent - TouchCancel → Capture is released, no event raised
Pointer Types
Use theIPointer.Type property to distinguish input types:
PointerType.Touch- Touch inputPointerType.Mouse- Mouse inputPointerType.Pen- Pen/Stylus input
Usage Examples
Detecting Touch Input
Multi-Touch Tracking
Detecting Double-Tap
Touch Drawing with Pressure
Implementing Touch-to-Pan
Differentiating Between Touch and Mouse
Touch-Specific Properties
ThePointerPointProperties class provides touch-specific information:
Pressure
Contact Area
Platform Considerations
Double-Tap Timing
Double-tap detection uses platform-specific timing:Touch Cancellation
Touch events can be cancelled by the system (e.g., when a system gesture is recognized):Best Practices
- Check Pointer Type: Always check
e.Pointer.Typeto handle touch differently from mouse when needed - Track by Pointer ID: Use
e.Pointer.Idto distinguish between multiple simultaneous touches - Handle Cancellation: Implement
OnPointerCaptureLostto handle system gesture interruptions - Use Intermediate Points: Call
GetIntermediatePoints()for smooth touch tracking - Respect Platform Timing: Use platform settings for double-tap detection timing
- Don’t Rely on Hover: Touch devices don’t have hover states
- Provide Touch-Friendly Targets: Use larger hit areas for touch input (minimum 44x44 pixels recommended)
- Test Multi-Touch: Test your app with multiple simultaneous touch contacts
- Handle Pressure: Check
Properties.Pressurefor pen input to enable pressure-sensitive drawing