Guilherme Torres Castro
Guilherme Torres Castro

Reputation: 15350

Xamarin forms background image for all Pages

It´s possible to set an image to be the background of all Pages on my application (for all platforms IOS, Android and WP) ?

Page has a BackgroundImage property, so I can create a base page, set the background and make all my pages extends from it.

I want to know if there is a more appropriate solution, to handle this.

Upvotes: 3

Views: 4688

Answers (1)

Sten Petrov
Sten Petrov

Reputation: 11040

You could use Styles in your App.cs :

public App ()
{
  Application.Current.Resources.Add(new Xamarin.Forms.Style(typeof(Page)){
                Setters = {
                    new Xamarin.Forms.Setter { Property = Page.BackgroundImageProperty, Value = "back.png"},
                }
            });
}

much less preferred or advised but for the sake of showing another option you could attach an event handler to your NavigationPages and set the background from there:

  yourRootNavigationPage.Pushed+= (sender, e) => e.Page.BackgroundImage = "back.png";

Upvotes: 4

Related Questions