Search code examples
xamlxamarinxamarin.forms

Could not load image named


I'm developing an application with Xamarin.Forms. I want to create an ImageButton, but I get this output:

[0:] Could not load image named: {0}: Image.png
[0:] FileImageSourceHandler: Could not find image or image file was invalid: File: Image.png

Here is my code :

<ImageButton  x:Name="Button" Grid.Row="44" Grid.Column="19" Grid.RowSpan="6" Grid.ColumnSpan="18" HorizontalOptions="CenterAndExpand" VerticalOptions="Center" Source="Image.png" Clicked="Button_Clicked" BackgroundColor="Transparent"  />

Image.png is in ./Media and code in ./Page.xaml

If I delete image from the directory, the application doesn't launch, because the image is not found. But, when the image is in the directory, the application launches and the output only appears when I load the page.

I have already tried to select Build action on Resource and rebuilding but the problem is still there.

I have also tried to put Image.png in Projet.Android/Resources/drawable with AndroidResource but no change.

Ps. I'm trying to launch the application on my android tablet.


Solution

  • I finally found the solution :

    In the Projet.Android/Resources/drawable folder, in addition to putting Build Action on AndroidResource, I must write MSBuild:UpdateGeneratedFiles in Custom Tool.

    Then, I relaunch my app and I have the images.