I have developed a windows phone application, i want that app to be run in light theme, irrespective of what user have set. means is there any way to set a default theme for
From http://developergoodies.blogspot.nl/2012/10/force-windows-phone-theme.html
(Tested and verified; get the themes; copied from resource to prevent future inaccessibility)
Answer
When the UI is designed specially for the dark theme it won't look well on the light theme, or vice versa.
To prevent this the application can force the default dark or light theme.
In the application class' constructor put this code to force the dark theme:
if ((Visibility)Application.Current.Resources["PhoneLightThemeVisibility"] == Visibility.Visible) MergeCustomColors("/Themes/DarkStyles.xaml");
Or this code to force the light theme:
if ((Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"] == Visibility.Visible) MergeCustomColors("/Themes/LightStyles.xaml");
Anywhere in your project put this method:
private void MergeCustomColors(String Theme)
{
ResourceDictionary Dictionaries = new ResourceDictionary();
String source = String.Format(Theme);
var themeStyles = new ResourceDictionary { Source = new Uri(source, UriKind.Relative) };
Dictionaries.MergedDictionaries.Add(themeStyles);
ResourceDictionary appResources = Current.Resources;
foreach (DictionaryEntry entry in Dictionaries.MergedDictionaries[0])
{
SolidColorBrush ColorBrush = entry.Value as SolidColorBrush;
SolidColorBrush ExistingBrush = appResources[entry.Key] as SolidColorBrush;
if (ExistingBrush != null && ColorBrush != null) { ExistingBrush.Color = ColorBrush.Color; }
}
}
The code assumes that the projects contains the files DarkStyles.xaml and LightStyles.xaml in a folder named Themes.