Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 75885

Styling a page

$
0
0

I'm trying to style a page in an XF app. I would like to set the style in one place and have that flow through to all of my screens. Unfortunately, I am doing something incorrect. I have the following code in my App class. The background is a white image. The background is the default black in the android emulator.

    public App()
    {

        Application.Current.Resources = new ResourceDictionary();
        var pageStyle = new Style(typeof(Page))
        {
            BaseResourceKey = Device.Styles.BodyStyleKey,
            Setters =
            {
                new Setter { Property = Page.BackgroundImageProperty, Value = "background.jpg"},
            }
        };
        Application.Current.Resources.Add(pageStyle);
        MainPage = new ContentPage();

Just to verify things, I put the following line in, and everything worked as expected. I just don't want to have to do this on every page. :-) I know that the image is there and readable as I want it to be.

MainPage.BackgroundImage = "background.jpg";

All suggestions are welcome. Thanks for your time. :-)

Wally


Viewing all articles
Browse latest Browse all 75885

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>