Overwrite WP7 Style Theme

I was working on a Windows Phone 7 application and the client wanted to always have the light theme and have a special accent color depending on settings inside the app. They wanted to do this for branding reasons so I had to find a way to always have this app look like it was in the light theme and override the accent color to the colors they wanted.

I will now go over how I did that. You can use this to always have the light theme for the app like the native mail app, or even create your own custom theme.

In the code I created a method in the App.xaml.cs file, and this method get called in the constructor for App() before the InitializePhoneApplication() call.

You will also need to set teh background on all the pages to {StaticResource PhoneBackgroundBrush} like

I tried to document the code so you can understand what is going on line by line so I will give a little explanation here.

The line

loads the theme you are going override. Here I copied a default theme resource file (Edit: the theme resource file is ThemeResource.xaml) from the design folder located on my machine at C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.1\Design\LightBlue and called it LightTheme.xaml. If you look in the design folder you will see many folders.

Then the code went though all the entries and compared the ResourceDictionaries, if the custom theme file contains the key name of a main style element, it will overwrite it’s brushcolor. If you look at a default theme resource file, it contains a bunch of colors with keys and the keys are pretty self explanatory. So if you wanted to create your own custom theme you can start by copying and editing one of those files.

Also in my code you see me checking a setting value and then overriding the accent color depending and the user setting. This isn’t required unless you want the user to select a special accent colors in the settings or want them to change, if you just want one over ridden accent color just put it into your style resource file.

And questions or comments just let me know and thank you for reading.

  1. Overwrite Windows Phone 7 Style Theme - pingback on March 16, 2012 at 6:14 am
  2. Looks like a neat solution. I just tried but can’t find any file named lightblue.xaml, the only files I see in that folder are:
    -lightBlue.DLL
    -System.Windows.xaml
    -Themeresources.xaml
    where can I find lightBlue.XAML? (or one of these themes)

  3. Looks like just what I needed, but I don’t know where you got the ‘Setting’ and the ‘IsolatedStorageGateway’ classes. Can you point me to where I can download them?

    • Those are part of a class file I created to handle all the application setting code. So in my code sample it was checking the user settings to determine what theme Accent Brush color should be used. So for your application you don’t need that part, but if you wanted the user to select what theme they want, then you will need to create your own “settings” and save the selected setting into storage. If you need help with that I will create a write up about creating an Isolated storage gateway class.
      I hope this helps if not, let me know and I will try to help you out.
      -Andrew

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Trackbacks and Pingbacks: