Question

I'm developing an application for a tablet with Windows 8. I'm subscribing for both TouchDown and StylusDown events. The problem is - when I make a touch with my finger, both events occur. TouchDown comes first, then comes StylusDown. When I make a touch with a stylus, only StylusDown occurs.

Is it a normal behavior for all the tablets? Or is it specific for some models?

I can't find any documents about this.

Was it helpful?

Solution

This is the standard flow for all touch events in WPF. If the TouchDown event is not marked as handled, it will fire as a StylusDown then as a MouseDown. You can stop this by handling the event, for example below:

protected override void OnTouchDown( TouchEventArgs e )
{
    // your code here
    e.Handled = true;
}

OTHER TIPS

When WPF was designed, there wasn't too much touch or stylus capable devices around. To keep old apps to responsive to new input devices such as touch screen or stylus, their events are transformed as follows (if it is not marked as handled):

  • Touch device: Stylus > Touch > Mouse
  • Stylus device: Stylus > Mouse

The problem starts when you would like to handle each input device event only when it comes from its corresponding real device, e.g. handle stylus events only if it comes from a real stylus device and not from a touch device, etc.

In case of Touch events, nothing special required, as it is fired only by real touch devices.

In case of Mouse events, the StylusDevice property can be used:

        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            if (e.StylusDevice != null) return;

            // This is a real mouse event

            base.OnMouseDown(e);
        }

In case of Stylus events, the StylusDevice.TabletDevice.Type property can be used:

        protected override void OnStylusButtonDown(StylusButtonEventArgs e)
        {
            if (e.StylusDevice.TabletDevice.Type != TabletDeviceType.Stylus) return;

            // This is a real stylus event

            base.OnStylusButtonDown(e);
        }

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top