Forum Libraries, Components, and Plugins


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Attaching touch event to CanvasView on android

Hi, I am new to xamarin and android development, and this is my first stab at it, so I am not sure I have got it entirely right.

My issue is that I can't get the touch event to fire.

I have gone through the documentation and guides to add touch to my canvasview, in other to pan and scale my image.
(can't post the link)

My problem with this is that my xml is not the same, is this because I am using android XML rather than xamarin xml? Either way, I could not get it to recognise the grid I surrounded the CanvasView with and was attaching the event too. It kept telling me there was an error expanding the class.

here is my current XML:

`<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="....."







    layout="@layout/toolbar" />


    android:text="Gregorian Date:"





    android:padding="3dp" />


    android:text="Metonic Date:"





    android:padding="3dp" />








(had to remove the xmlns link to post)

As you can see I have now tried to add the touch events directly to the CanvasView, and handle them in the code behind, as I read that was possible. I had to edit the code in the tutorial to use SKTouchAction and remove a xamarin.Forms.Point, but other than that is was pretty painless. Here is the method signature I found online to attach to the event. I notice that this was in a ContentView, and is this again the "xamarin forms way"?

void OnTouchEffectAction(object sender, SKTouchEventArgs args) { ...

And this doesn't seem to fire? So I tried to attach the event in the code behind

canvasView.Touch += OnTouchEffectAction;

but that seems to want a method with the signature:

void OnTouchEffectAction(object sender, View.TouchEventArgs args) { ...

So I guess that is why it is not firing from the XML.

How can I attach this touch event given my XML? I don't want to have to change to the "xamarin forms way" at this stage, I am only targeting android, and the app is almost done! What am I missing?


  • saishaiksaishaik INMember ✭✭

    Hi @RadicalGeek , I am also looking exactly as yours. Did you make it to be worked any way? If so can you please guide me with?

Sign In or Register to comment.