user3841879
user3841879

Reputation: 659

Xamarin Forms ImageButton - image not showing

Currently using the Xamarin.Forms.Labs library and when I use ImageButton, only the text appears and not the image:

var bttn = new ImageButton {
                BackgroundColor = Xamarin.Forms.Color.Transparent,
                Text = "Button",
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Source = "image.png",
                Orientation = Xamarin.Forms.Labs.Enums.ImageOrientation.ImageToLeft,
                ImageHeightRequest = 50,
                ImageWidthRequest = 50,
                WidthRequest = 150,
                HeightRequest = 150,
            };

Why is it not showing the image?

Upvotes: 0

Views: 4358

Answers (2)

Jesse
Jesse

Reputation: 2684

If the resource image is named my_image.png then you would use the property Image="my_image":

var leftMenuButton = new Xamarin.Forms.Labs.Controls.ImageButton 
{
    Image="my_image",
    ImageHeightRequest = 10,
    BackgroundColor = Color.Transparent,
    BorderColor = Color.Black
};

Upvotes: 1

That Tech Guy
That Tech Guy

Reputation: 21

I have run across this issue and it drove me crazy! This is how you go about fixing it. Let me know if this helps you out.

iOS : Make sure you added the necessary implementation within the AppDelegate.cs file. Just replace what you currently have with the following and make sure you are using Xamarin.Forms.Labs.iOS

`public partial class AppDelegate : XFormsApplicationDelegate`

Android : Make sure you added the necessary implementation within the MainActivity.cs file. Just replace what you currently have with the following and make sure you are using Xamarin.Forms.Labs.Droid

`public class MainActivity : XFormsApplicationDroid`

Upvotes: 2

Related Questions