2

I would like to know please, how to prevent WPF promoting mouse events when the source of the event is a touch ?

I read the article of JoshB here but, the mouse events keep getting triggered, although I did e.Handled = true;

Here is what JoshB says:

The touch event flow with no manipulations. The touch events are unhandled, so WPF promotes the event to the mouse equivalent

So, I tried in my code to mark the event as handled, but WPF still promotes mouse events once I touch the _touchSurface which is InkSurface

Here is my code: ( I am not using Microsoft Surface SDK )

_touchSurface.IsManipulationEnabled = true;
_touchSurface.TouchDown += new EventHandler<TouchEventArgs>(touchDown);
_touchSurface.TouchMove += new EventHandler<TouchEventArgs>(touchMove);
_touchSurface.TouchEnter += new EventHandler<TouchEventArgs>(touchEnter);
_touchSurface.TouchLeave += new EventHandler<TouchEventArgs>(touchLeave);

_touchSurface.ManipulationDelta += new EventHandler<ManipulationDeltaEventArgs>(ManipulationDelta);
_touchSurface.ManipulationStarting += new EventHandler<ManipulationStartingEventArgs>(ManipulationStarting);
_touchSurface.ManipulationCompleted += new EventHandler<ManipulationCompletedEventArgs>(ManipulationCompleted);


void touchDown(object sender, TouchEventArgs e)
{
e.Handled = true;
}
void touchMove(object sender, TouchEventArgs e)
{
e.Handled = true;
}
void touchLeave(object sender, TouchEventArgs e)
{
e.Handled = true;
}


void ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
    e.Handled = true;
}

void ManipulationStarting(object sender, ManipulationStartingEventArgs e)
{
    e.Handled = true;
}
void ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
   e.Handled = true;
}
H.B.
  • 166,899
  • 29
  • 327
  • 400
simo
  • 23,342
  • 38
  • 121
  • 218

2 Answers2

1

If you don't want mouse events to get promoted, then you don't need to handle TouchDown and set e.Handled = true. Then the manipulation code will step in and you won't get mouse events.

torvin
  • 6,515
  • 1
  • 37
  • 52
0

Samir: I had just this same issue too. Have you tried deriving a class from that UIElement based component and override the Mouse and Touch events(rather than setting event handlers )?

https://github.com/100kph/TouchMousePromotion has an example stub

Ady
  • 104
  • 3