Xamarin creates background image for all pages

Is it possible to set the background image of all pages in my application (for all IOS, Android and WP platforms)?

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

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

+3


source to share


1 answer


You can 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 recommended, but to demonstrate another option, you can attach an event handler to yours NavigationPage

and set the background from there:

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

      

+4


source







All Articles