Edward
Edward

Reputation: 7424

How to apply style to application bar globally?

I checked the Application bar but no style attribute is shown. I have about 10 pages that use an app bar so it would be ideal to set a style in the Application.Resources. Is it possible to apply a style to all application bars in my application?

Upvotes: 1

Views: 1269

Answers (2)

William Melani
William Melani

Reputation: 4268

You can pretty much do this with a abstract class which your pages inherit from.

public abstract class BasePage : PhoneApplicationPage
    {
        public abstract bool UsingApplicationBar { get; }

        public Color ApplicationBarColor= Colors.Gray;

    public BasePage()
    {
        Loaded += BasePageLoaded;

    }

    private void BasePageLoaded(object sender, RoutedEventArgs e)
    {
        if (UsingApplicationBar)
        {
            ApplicationBar.BackgroundColor = ApplicationBarColor;
        }

    }
}

Upvotes: 2

Divya
Divya

Reputation: 2622

As far as I understand your question, you have different application bars on different pages and you want to have a style which can be applied to all. Unfortunately, binding does not work with application bars. You may have to style all of them one by one. For more information: Windows Phone ApplicationBar BackgroundColor property style XamlParseException

Upvotes: 1

Related Questions