4

Please let us know how to create Image Button in Xamarin.Forms, we aren't using the story board.

Environment : Xamarin Studio on Mac

Gerald Versluis
  • 30,492
  • 6
  • 73
  • 100
user1027076
  • 175
  • 1
  • 4
  • 12

2 Answers2

8

A lot of ways, like this one:

var button = new Image { ... }; // make your image your button should be
button.GestureRecognizers.Add (new TapGestureRecognizer (sender => {
  // Do whatever you want to do when its tapped
  button.Opacity = 0.6;
  button.FadeTo (1);
}));

Or you can even use Xamarin forms labs:

https://github.com/XLabs/Xamarin-Forms-Labs

Or like @Gerald Versluis say:

With image property of the button.

Image="logo.jpg"
Mario Galván
  • 3,964
  • 6
  • 29
  • 39
2

Actually

Xamarin.Forms.TapGestureRecognizer.TapGestureRecognizer(System.Action)

is obsolete: 'Obsolete in 1.0.2. Use Command instead

Try like this one:

  var CallButton = new Image { Source = "call.png" };
      CallButton.GestureRecognizers.Add(new TapGestureRecognizer
             {
              Command=new Command(()=> {
                // Do whatever you want to do when its tapped
                  })
              });

For More info, Check the following link:

http://www.c-sharpcorner.com/UploadFile/e04e9a/xamarin-forms-image-button-recipe/

Mohamad Mahmoud Darwish
  • 3,865
  • 9
  • 51
  • 76