Here on MSDN , you'll find code examples that you can use to determine your current topic — by comparing resources. For instance:
private bool IsDarkTheme() { return (double)Application.Current.Resources["PhoneDarkThemeOpacity"] > 0; }
But - I have included some issues that execute the above line in the WP8.1 Runtime - it could not find the requested key. As it turned out, the above code will only work on WP8.1 Silverlight (also WP8.0) .
But (again) nothing stands in your way to define your own ThemeResource and check its status:
In app.xaml - define some ThemeResources:
<Application.Resources> <ResourceDictionary> <ResourceDictionary.ThemeDictionaries> <ResourceDictionary x:Key="Light"> <x:Boolean x:Key="IsDarkTheme">false</x:Boolean> </ResourceDictionary> <ResourceDictionary x:Key="Dark"> <x:Boolean x:Key="IsDarkTheme">true</x:Boolean> </ResourceDictionary> <ResourceDictionary x:Key="Default"> <x:Boolean x:Key="IsDarkTheme">false</x:Boolean> </ResourceDictionary> </ResourceDictionary.ThemeDictionaries> </ResourceDictionary> </Application.Resources>
Then you can use, for example, a property in your code:
public bool IsDarkTheme { get { return (bool)Application.Current.Resources["IsDarkTheme"]; } }
Please also note that in some cases you may need to check HighContrast - according to MSDN you can do this by setting the AccessibilitySettings class or expand your own created ThemeResource object with HighContrast values.
source share