jpattersonCSpeed
Topic Author
Posts: 7
Joined: 10 Mar 2020, 21:27

Cannot tap an image to trigger a click event when manipulation events are subscribed to

17 Mar 2020, 21:52

Hello again,

I have an image that manipulations can be performed on to zoom and pan it using ManipulationStarting, ManipulationInertiaStarting, ManipulationDelta, and ManipulationCompleted events that are managed by a ViewModule base class:
public abstract class ManipulationViewModuleBase : ModuleViewBase
{
   public ManipulationViewModuleBase(IEventAggregator ea) : base(ea)
   {
   }

   protected void SubscribeManipulations(UIElement control)
   {
      control.IsManipulationEnabled = true;
      control.ManipulationStarting += StartManipulation;
      control.ManipulationInertiaStarting += StartingManipulation;
      control.ManipulationDelta += ChangeManipulation;
      control.ManipulationCompleted += CompleteManipulation;
   }

   protected void UnsubscribeManipulations(UIElement control)
   {
      control.ManipulationStarting -= StartManipulation;
      control.ManipulationInertiaStarting -= StartingManipulation;
      control.ManipulationDelta -= ChangeManipulation;
      control.ManipulationCompleted -= CompleteManipulation;
      control.IsManipulationEnabled = false;
   }

   protected void StartManipulation(object sender, ManipulationStartingEventArgs e)
   {
      // Acknowledge that the manipulation is starting and set some values
      e.Handled = true;
   }

   protected void StartingManipulation(object sender, ManipulationInertiaStartingEventArgs e)
   {
      // Handle some manipulation start setup
      e.Handled = true;
   }

   protected void ChangeManipulation(object sender, ManipulationDeltaEventArgs e)
   {
      // Handle deltas in the manipulation
      e.Handled = true;
   }

   protected void CompleteManipulation(object sender, ManipulationCompletedEventArgs e)
   {
      // Handle manipulation complete
      e.Handled = true;
   }
}
Inside of the code behind for a view that extends this class, we find an Image that needs to be manipulated and call
SubscribeManipulations(ImageControl)
to set up the touch manipulations.

I would also like to be able to tap the image to perform an action, and have the MouseDown event of the image subscribed to with a handler that is in the code behind of the view. Clicking on the image with a mouse causes the MouseDown event to trigger, but tapping on the image always causes the ManipulationEvents to trigger. Removing the ManipulationEvents allows the MouseDown event to be triggered when tapping the image. I've also seen buttons that have handlers subscribed to their MouseDown events work when tapped.

Is it expected that subscribing to manipulation events causes taps to not register as clicks? If it is, is there an easy way to mimic tapping behavior?
 
User avatar
jsantos
Site Admin
Posts: 2802
Joined: 20 Jan 2012, 17:18
Contact:

Re: Cannot tap an image to trigger a click event when manipulation events are subscribed to

19 Mar 2020, 21:05

Is it expected that subscribing to manipulation events causes taps to not register as clicks? If it is, is there an easy way to mimic tapping behavior?
Yes, right now we are WPF compliant and manipulations absorb normal events. We have plans to migrate to the UWP approach where manipulations and clicks follow different routes.

We are also working in implementing high-level events like Tap so if this is not very critical for you I would wait. If you need a solution right now, I would implement the 'Tap' event by checking inside CompleteManipulation if the touch position only moved "a bit" and time ellapsed since StartManipulation is small. Please, let me know if you need more help about this.
 
jpattersonCSpeed
Topic Author
Posts: 7
Joined: 10 Mar 2020, 21:27

Re: Cannot tap an image to trigger a click event when manipulation events are subscribed to

30 Mar 2020, 20:42

Alright thanks. I am interpreting taps based on manipulation events that are relatively short where the user doesn't move too much.

Who is online

Users browsing this forum: No registered users and 11 guests