//OverwriteTheme is the function to overwrite the dark or light theme to your own custom theme.
//You can either create your own theme, or copy a theme from the design folder in the WP7 SDK
private void OverwriteTheme()
{
//A string that contains the location to your custom theme file
string source = String.Format("/SampleApp;component/Resources/LightTheme.xaml");
//Creates a resourceDictionary file that contains all the data for your custom theme
var customThemeStyle = new ResourceDictionary { Source = new Uri(source, UriKind.Relative) };
//Creates a resourceDicionary of the current theme data
ResourceDictionary appResources = App.Current.Resources;
//Cycle through each entry in the custom Theme ResourceDictionary and check if
//there is a matching key resource. If so overwrite the current theme color brush
//with the custom color brush.
foreach (DictionaryEntry entry in customThemeStyle)
{
//Gets the SolidBrushColor of the current custom entry
SolidColorBrush colorBrush = entry.Value as SolidColorBrush;
//Looks to see if there is a current theme entry with matching key
SolidColorBrush existingBrush = appResources[entry.Key] as SolidColorBrush;
//If both SolidBrushColor variables are not null, overwrite current resource with custom resource
if (existingBrush != null && colorBrush != null)
{
existingBrush.Color = colorBrush.Color;
}
}
//This loads the settings from the application
Setting settings = new Setting();
IsolatedStorageGateway settingStorage = new IsolatedStorageGateway(StorageType.Setting);
settings = settingStorage.LoadSettings();
//Checks to see what theme setting is selected, and then overwrite the accent Color with the custom accent color
if (settings.ThemeSettingID == 0)
{
(App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush).Color = Color.FromArgb(255, 255, 129, 24);
}
else if (settings.ThemeSettingID == 1)
{
(App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush).Color = Color.FromArgb(255, 246, 119, 189);
}
}