xamarin.iosxamarin.formsxamarin-studio

How do Image Click Event works on Xamarin Forms - iOS Apps?


I am relatively new to Xamarin Forms : iOS Apps. Just like any other Apps, I have to create an event on an Image. Home , Back , Account setting.

Whether these events are fired on Image Button Event ?


Solution

  • There is no click event for the image. You have to create a Tap Gesture Recognizer for the image.

    Xaml:

    <Image Source="imageName.png">
        <Image.GestureRecognizers>
            <TapGestureRecognizer
                    Tapped="OnImageNameTapped"
                    NumberOfTapsRequired="1" />
      </Image.GestureRecognizers>
    </Image>
    

    Xaml.cs:

    void OnImageNameTapped(object sender, EventArgs args)
        {
            try
             {
                //Code to execute on tapped event
             }
            catch (Exception ex)
             {
               throw ex;
             }
        }