Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Forms - Load image in a Button

I looked extensively online but I couldn't find anything really specific to help me out in this trouble I am having.

I am trying to make a custom renderer for a Button component, in Xamarin forms. Why am I not using the XLabs ImageButton component? Because it's not compatible with Android 4.0.3, which is my current Android target version.

I also tried writing on my own some code that is that much worthless that I am quite shy to post, unless you really require me to :)

I am in need of this code because, without it, images just fail to load in buttons while trying to use them in any button like this:

<Button Image="someImage.png"/>

I tried following a tutorial, here:

http://blog.falafel.com/learning-xamarin-custom-renderers-in-xamarin-forms/

But I failed adapting it to my needs.

like image 661
Guido Magrin Avatar asked Jan 08 '23 20:01

Guido Magrin


1 Answers

Are no images being displayed at all? Check your locations of the images. Default location in ios is Resources folder, in android it is resources/drawable and in wp it is the root. If you want one image rather than 3 for each solution, put in to the PCL and set the build property to embedded resource and qualify the name with the namespace it is in. ie... ProjectName.Assets.image.png if it is in the PCL Assets directory. Not sure if this is your problem or not, but figured I would offer it up , just in case.

like image 135
Russ Fustino Avatar answered Jan 17 '23 17:01

Russ Fustino