TomTom
TomTom

Reputation: 321

How do you change the background colour of the toolbar on Windows Phone in Xamarin Forms?

We are using Xamarin Forms (and have recently upgraded to 2.0.0.6484). We are targeting iOS, Android and Windows (8.1 and UWP). We are adding items to the toolbar on a page by page basis on the Windows platform e.g. ToolbarItems.Add(new ToolbarItem("Sample", "icon.jpg", () => { }));. Now we would like to change its background colour.

I can do this easily in the native windows environment like as shown in this image, however you can not seem to do this in Xamarin Forms as there is no renderer or relevant properties exposed. Works fine on the native platform development environment

A look into the issue on the Xamarin Forums and we find issues from a year a go (of a similar nature) that have yet to be solved.

So how can we change the background colour of a CommandBar in Xamarin Forms? Or how can we avert the issue?

Upvotes: 2

Views: 5576

Answers (2)

Crystoline
Crystoline

Reputation: 111

Do this in App.xaml

<Application.Resources>
        <ResourceDictionary>
            <Color x:Key="mRed">#DD0000</Color>
            <Color x:Key="mWhite">#FFFFFF</Color>

            <Style TargetType="NavigationPage">
                <Setter Property="BarBackgroundColor"  Value="{ StaticResource mRed}"/>
                <Setter Property="BarTextColor"  Value="{ StaticResource mWhite}"/>
            </Style>
        </ResourceDictionary>
    </Application.Resources>

Visual Studio 2017 Sample Project - Screenshot

Upvotes: 4

Adam
Adam

Reputation: 16199

You need to do it at the native level as I don't know of any exposed properties.

Windows Phone

this.ApplicationBar.BackgroundColor = 

iOS and Android don't have an ApplicationBar they put any toolbar items in the NavigationBar

NavigationPage.BarBackgroundColor =

Upvotes: 0

Related Questions