Add tap events to elements inside an SVG using SkiaSharp in Xamarin.Forms

AditkothariAditkothari USMember ✭✭

I want to add tap events inside the SVG ,want to get location or specific any detail .Is it possible?


  • GraverobberGraverobber Member ✭✭✭
    edited July 1

    You're giving really little information what you want to achieve or what you already tried. Especially what your code looks like is missing.

    If your view you want to get the tap in inherits from SKCanvasView, then you can override theOnTouch(SKTouchEventArgs args) method.
    The args will contain all the information like location and state.

    Make sure to set EnableTouchEvents to true for your SKCanvasView otherwise the touch callback will not be fired.
    Also make sure to let the view know that you actually handled the touch by setting args.Handled = true or false depending on the state of the touch and if you handled it.

  • AditkothariAditkothari USMember ✭✭

    @Graverobber Thank you for help .Sorry I have basically not started the developing so won't be able to share the code ,as you said OnTouch event it is firing everytime when I am tapping ,I want to touch the specific points inside it and get to able the details.

  • GraverobberGraverobber Member ✭✭✭

    I'm sorry @Aditkothari I can not fully understand what exactly you need.
    If you need the touch event for just specific positions in your view, then you can take the Location value from your args in OnTouch and check if it is within range:

    For example:

    protected override void OnTouch(SKTouchEventArgs args)
        if(args.Location.X > areaStartX && args.Location.X <areaEndX && argsLocation.Y > areaStartY && args.Location.Y < area.EndY)
        //You touched in the desired position

    Was it what you asked?

Sign In or Register to comment.