Created
April 26, 2013 13:16
-
-
Save nivesh2/5467318 to your computer and use it in GitHub Desktop.
detect Theme in Windows Phone app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Accent color is given by PhoneAccentColor ressource. Its type is System.Windows.Media.Color | |
| using System.Windows.Media; | |
| Color AccentColor() | |
| { | |
| return (Color)Application.Current.Resources["PhoneAccentColor"]; | |
| } | |
| //To make a TextBlock theme-aware use the Style property | |
| <TextBlock Style="{StaticResource PhoneTextAccentStyle}"/> | |
| //To make a Rectangle theme-aware use the Fill property: | |
| <Rectangle Fill="{StaticResource PhoneAccentBrush}" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //To get theme background, you can use PhoneDarkThemeVisibility resource. Its type is System.Windows.Visibility enum | |
| using System.Windows | |
| bool DarkThemeUsed () | |
| { | |
| return Visibility.Visible == (Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"]; | |
| } | |
| bool LightThemeUsed() | |
| { | |
| return Visibility.Visible == (Visibility)Application.Current.Resources["PhoneLightThemeVisibility"]; | |
| } | |
| ... | |
| // Write the theme background value. | |
| if (DarkThemeUsed ()) | |
| { | |
| //Set resources according to dark theme | |
| } | |
| else | |
| { | |
| //Set resources according to light theme | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment