Created
March 9, 2015 00:32
-
-
Save rootasjey/81df7ccea60e56e6cd75 to your computer and use it in GitHub Desktop.
Check Windows Phone 8.1 Theme and set a source property of an Image control
This file contains 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
/// <summary> | |
/// This function checks if the light theme is active | |
/// and select black icons if it's the case | |
/// </summary> | |
private void CheckIconTheme() | |
{ | |
// Get the current Phone Background Theme (dark or light) | |
SolidColorBrush brush = (SolidColorBrush)Resources["PhoneBackgroundBrush"]; | |
// If the light theme is active, | |
// replace white icons with black ones | |
if (brush.Color.Equals(Colors.White)) { | |
// Create a new BitmapImage which will be | |
// the source of the Image Control defined in the xaml part | |
BitmapImage bmi = new BitmapImage(); | |
bmi.CreateOptions = BitmapCreateOptions.IgnoreImageCache; | |
// Set the URI that represents the path where the icon is located | |
// Note that the path is prefixed with the required 'ms-appx:'. | |
// The icons is in the phone's local storage | |
bmi.UriSource = new Uri(" ms-appx:/Assets/Icons/iconCancel-black.png", UriKind.RelativeOrAbsolute); | |
// These next 4 lines define the Source for the Image control | |
CloseUsername.Source = bmi; | |
CloseLanguage.Source = bmi; | |
CloseDynamictile.Source = bmi; | |
CloseBackground.Source = bmi; | |
} | |
else { | |
// This means that the black theme is selected. | |
// By default my icons are black | |
} | |
} | |
// The code of the Image in the xaml part looks like this | |
// <Image x:Name="CloseUsername" | |
// Height="25" Width="25" | |
// Source="/Assets/Icons/iconCancel-white.png" | |
// Margin="10,0,0,0" | |
// RenderTransformOrigin="0.5,0.5"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment