请告诉我们如何在Xamarin.Forms中创建图像按钮,我们不使用故事板。
环境:Mac上的Xamarin Studio。
环境:Mac上的Xamarin Studio。
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"
实际上,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/