Search code examples
c#androidxamarintouchdrawing

Xamarin Touch Tracking (for drawing with SkiaSharp)


Today, I have another question about Xamarin. In the Xamarin documentation there is something about Touch Tracking, what I want is using the SkiaSharp Namespace to do some drawing as user input. So, the user uses his fingers to draw something on a BoxView or something like that.

Problem: it's hard to find the namespaces, no trace in the xamarin documentation. Just that the name is "TouchTracking" and I need "TouchEffects" too.

I googled a little and all i got is some 0.1.0 beta stuff where the TouchEffects are not even in the same namespace, but they are in the provided code example, which wouldn't really matter, but the one I found is not for cross-platform and this really bothers me because I have the ambition to do everything via crossplatform if possible.

So are there cross-platform solutions for touch drawing?


Solution

  • I really hate to answer my own questions but by accident i found out, that SkiaSharp actually supports everything we need. Which is pretty amazing, since after my google research i found out EVERYBODY is looking for it and it seemed only MR Gestures does support what i was looking for. To the point: SKCanvasView has a Touch event with arguments (object, SKTouchEventArgs). those event args provide everything you need to draw on the surface, position, type of action (pressed, released, exited, entered, cancelled, ...) but please notice: you need to enable the handling with setting 'Handled' true, if not the event args will return just Pressed. Also you have to enable the Touch Input when creating the SKCanvasView.

    Someone should add this to the page provided in the previous answer.