Viktor_DE Viktor_DE - 6 months ago 65
C# Question

How to route touch events to separate controls UWP C#

I am facing a major problem for custom touch event handling.
The goal is to route the touch event to different controls, depending on how many fingers are used.

For example:
We have a scrollview with many webviews arranged in it.
The zoomfactor is set to present one webview to fullscreen.

Currently I am using the pointer pressed / released functions like this, to configure the controls, so the event will be catched by the right one:

int pointerCount = 0;

private void ScrollView_PointerPressed(object sender, PointerRoutedEventArgs e)
if (pointerCount > 3)
pointerCount = 0;

switch (pointerCount)
case 1:
// I don't do anything, so it goes to the webview anyway
case 2:
case 3:
catch (Exception ex)

private void EnableScrolling()
ScrollViewer.ZoomMode = ZoomMode.Enabled;
ScrollViewer.VerticalScrollMode = ScrollMode.Enabled;
ScrollViewer.HorizontalScrollMode = ScrollMode.Enabled;

  • 1-finger events should go to the webview // this works

  • 2-finger events should go to the ScrollView // this is not working, because the webview grabs the touch event and will not release it again

  • 3-finger events should zoom out // this works

The PointerPressed is always called, but the PointerReleased is not called when the PointerPressed was on the webview.

This also results in the effect of not decreasing the pointerCount, so it is possible to do a 1-finger tap 3 times and it results in the 3-finger event and zooms out, that should not happen.

Hopefully you can see the problem and help to resolve it.
If you think this is a way too wrong approach, feel free to show an alternative that works out better.


I figured out how to handle that, and it is so simple that I could cry...

I just added this line of code to tell the webviews js that there was a event...

await webView.InvokeScriptAsync("eval", new string[] { "document.elementFromPoint(" + pointX + ", " + pointY + ").click();" });

And the webview handles the rest of it. So there is no custom invoke as I was worried about, it's just the standard function invoked, that is always invoked when a touch/click is performed.