Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Phone 8 Change Accent and Theme Colour

I am creating an Application for Windows Phone 8, and I would like to change the theme colour irrespective of the theme set by the user in the phone OS, in the same way that other applications do this (for example Skype).

So far I have only managed to change the background colour, by accessing the LayoutRoot element in XAML:

this.LayoutRoot.Background = new SolidColorBrush(Colors.White);

And the Foreground Colour:

(App.Current.Resources["PhoneForegroundBrush"] as SolidColorBrush).Color = Colors.Green;

However the following does not work on Windows Phone 8:

(App.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush).Color = Colors.White;
(App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush).Color = Colors.Yellow;

I do not know why I cannot change the PhoneBackgroundBrush or the PhoneAccentBrush and I have tried googling solutions however they only work with the windows phone 7 SDK.The Tutorial here works on WP 7 but not WP 8.

Thank you!

like image 614
Seb123 Avatar asked Jan 26 '13 12:01

Seb123


1 Answers

Fabrice is definitely on the right track. Getting the default PhoneAccentBrush and changing it's color is the way to go.

Add this code to the end of your App's constructor and it would override WP8's Accent colour for your app:

    Resources.Remove("PhoneAccentColor");
    Resources.Add("PhoneAccentColor", Colors.Magenta);
    ((SolidColorBrush)Resources["PhoneAccentBrush"]).Color = Colors.Magenta;

When we run this code and click a <Button /> you can see the new Accent colour:

Clicked button with Magenta background

like image 166
JustinAngel Avatar answered Sep 17 '22 08:09

JustinAngel