Madhav Shenoy
Madhav Shenoy

Reputation: 756

Add a background image using Styles : Xamarin Forms

I want to add a background image to my Xamarin Forms App. I've tried the solution defined here : Xamarin forms background image for all Pages. But this doesn't seem to work. I've also tried setting it via Xaml like this

<Style TargetType="ContentPage">
    <Setter Property="BackgroundImage" Value="MyImage.jpg" />
</Style>

To no avail. Any pointers would be appreciated. I'm working on Xamarin Forms version 2.3.2.127

Upvotes: 1

Views: 1552

Answers (1)

Stephane Delcroix
Stephane Delcroix

Reputation: 16232

You are defining an implicit Style for ContentPage, and if it's defined at the Application level ResourceDictionary it will be applied to all ContentPages.

With the scarce context and information you are giving, I can only guess what's going on. You probably have no ContentPages in your app, but multiple pages inheriting from ContentPage. If you want that to work, you have to set the property ApplyToDerivedTypes to true in your Style:

<Style TargetType="ContentPage" ApplyToDerivedTypes="true">
    <Setter Property="BackgroundImage" Value="MyImage.jpg" />
</Style>

Upvotes: 4

Related Questions