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">
SO, how do I fix it?
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:
Check the Build Action
of that image and ensure that it is assigned AndroidResource
. Rebuild and re-test.