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

4
请告诉我们如何在Xamarin.Forms中创建图像按钮,我们不使用故事板。
环境:Mac上的Xamarin Studio。

在 Xamarin 表单中,按钮具有图像属性...您可以设置如下... <Button Image="logo.jpg"/> - Heena
2个回答

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 Forms Labs:

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

或者像 @Gerald Versluis 所说:

使用按钮的图像属性。

Image="logo.jpg"

带有按钮的图像属性,使文本显示在图像旁边。如何才能让文本出现在图像上方? - Sonali
在XAML中做这件事是可能的吗? - rraallvv

2

实际上,Xamarin.Forms.TapGestureRecognizer.TapGestureRecognizer(System.Action)已经过时了:'自1.0.2版本起,请使用Command替代。

尝试像这样:

  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/


@user1027076,请检查这个解决方案。 - Mohamad Mahmoud Darwish

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接