Reputation: 491
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!
Upvotes: 11
Views: 20289
Reputation: 12465
If you want different brushes, then create new brushes. No need to go through the trouble to replace existing ones. One day you may want to use those built in brushes.
I would suggest just adding new resources to your app and reference those.
<Application.Resources>
<SolidColorBrush x:Key="AppAccentBrush" Color="#012345"/>
</Application.Resources>
In your pages, reference it like such
<TextBlock Text="Custom Accent" Style="{StaticResource PhoneTextNormalStyle}"
Foreground="{StaticResource AppAccentBrush}"/>
Upvotes: 8
Reputation: 16102
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:
Upvotes: 11
Reputation: 931
I saw a blog post a few days ago:
http://www.rudyhuyn.com/blog/2013/01/18/forcer-un-theme-sous-windows-phone-8/
It's in french but don't be afraid.
There is a sample to change the color in Windows Phone 8 (check the method DarkTheme())
Upvotes: 3