如何在Xamarin.Forms中创建图像按钮?

时间:2015-05-07 13:15:00

标签: xamarin xamarin.forms xamarin.mac

请告诉我们如何在Xamarin.Forms中创建图像按钮,我们不使用故事板。

环境:Mac上的Xamarin Studio

2 个答案:

答案 0 :(得分:8)

很多方面,比如这个:

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);
}));

或者你甚至可以使用Xamarin表格实验室:

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

或者像@Gerald Versluis说:

使用按钮的图像属性。

Image="logo.jpg"

答案 1 :(得分:2)

实际上

  

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

     
    

已过时:'在1.0.2中已过时。改用命令

  

尝试这样:

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

有关详细信息,请查看以下链接:

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