imageThe Windows Phone OS has a global Theme setting available for the user to change. This one setting affects every application. The Windows 8 seems to take a different approach (at least in Windows 8 RP): There’s no global theme setting, instead it’s up to the developer to decide if her application uses the dark or the light theme.

Defining the application theme in XAML

Maybe the easies way to define the application theme for the Metro application is to use the App.xaml. The Application-element has a RequestedTheme-attribute which can be set to either Dark or Light.


The App.xaml route works well if the theme is hard coded. But if the user can customize app’s theme, it’s maybe easier to set the theme in code.

Defining the application theme in code

The application theme can be set in the constructor of the App-class using code.

RequestedTheme = ApplicationTheme.Light;

The application theme cannot be changed when the application is running and trying to set it throws an exception. For example the OnLaunched-method in App.xaml.cs is already too late.

You could read the theme from application’s settings, making the theme configurable. Here’s an example where the current theme is stored in to application’s roaming settings:

var settings = Windows.Storage.ApplicationData.Current.RoamingSettings;

string currentTheme = null; 
if (settings.Values.ContainsKey("currentTheme")) 
    currentTheme = settings.Values["currentTheme"] as string; 

settings.Values.Add("currentTheme", currentTheme == "light" ? "dark" : "light");

And here’s App’s constructor where values is read:

public App() 
    this.Suspending += OnSuspending;

    var settings = Windows.Storage.ApplicationData.Current.RoamingSettings;

    if (settings.Values.ContainsKey("currentTheme") && (string) settings.Values["currentTheme"] == "light") 
        RequestedTheme = ApplicationTheme.Light; 
        RequestedTheme = ApplicationTheme.Dark; 

Note that the RequestedTheme-attribute in App.xaml seems to override the value set in the App’s constructor.

Defining the application theme for the Visual Studio designer

It’s possible to test both of the themes without running the app, using the Device-dialog.


You can switch between the Dark and the Light theme easily. The same dialog has other interesting options too, like the ability to switch the device inside the designer to the portrait mode.

Theme definitions

The XAML of the different themes are available from the following location: C:Program Files (x86)Windows Kits8.0Includewinrtxamldesignthemeresources.xaml



Comment by maillot de foot

maillot de foot...

Great, thanks for sharing this blog article.Really looking forward to read more. Fantastic....

Comment by vivien

Anibody know if it is allowed to switch during runtime and how?

Comment by peng liu

wp 8.1 ,change the light theme,the status bar will also light and then the some status bar label can not to display. how to fix it ?

peng liu