Xamarin.Forms Xaml background Image

Biellx picture Biellx · Aug 23, 2016 · Viewed 28k times · Source

I just started a Xamarin.Forms application and I want to add a background image to my XAML. I added the attribute but it does not appear when I run it!! Here is the images.

APP

public class App : Application
{
    public App()
    {
        // The root page of your application
        MainPage = new Page();
    }

XAML:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="App1.Page"
         BackgroundImage="bg.png">

enter image description here

SO, how do I fix it?

enter image description here

Answer

SushiHangover picture SushiHangover · Aug 23, 2016

Add your bg.png file in each of your native projects, since you are currently using a Android emulator start with your Xamarin.Android project:

Android - Place images in the Resources/drawable directory with Build Action: AndroidResource

ref: https://developer.xamarin.com/guides/xamarin-forms/working-with/images/

Example: In your Xamarin.Android project, add bg.png as shown:

enter image description here

Check the Build Action of that image and ensure that it is assigned AndroidResource. Rebuild and re-test.