Change theme when developing a Metro app

When creating a Metro-app for Windows 8, you as a developer can choose to use a light or dark theme for the application. For those of you that have previously developed for Windows Phone 7, this is nothing new.

The theme is predefined and when you are using Dark (which is default by the way), the background will be dark and text and so on will be set to light colors. When using the Light theme it is the other way around. You can of course customize everything.

So how do you change from Dark to Light theme for the app?
Here follows one simple example of how to do this.

First, locate your App.xaml-file in your solution. It will be in the root of your project. Open the code behind section and locate the constructor. Then add this line for light theme;
App.Current.RequestedTheme = ApplicationTheme.Light;
or for dark theme use;
App.Current.RequestedTheme = ApplicationTheme.Dark;

The result should now look like:
[sourcecode language=”csharp”]
public App()
//The following line changes the theme for the application. Use ApplicationTheme.Dark for dark theme.
App.Current.RequestedTheme = ApplicationTheme.Light;
this.Suspending += OnSuspending;