SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Windows Phone Application Development Tutorials, Articles and Resources for Mobile App Programmers


How to Detect Windows Phone Theme by Code

In Windows Phone app development it is important to detect Windows Phone theme selected by the smartphone user by programmatically in Windows Phone 8 app code. Your Windows Phone 8 app must be compatible with Windows Phone light theme and Windows Phone dark theme. Actually this is related with the graphics you used in your app. If you design your app considering only the dark theme, some icons, buttons or images may not be seen when the user selects Windows Phone Light theme from settings app.

So it is important to detect Windows Phone 8 theme (light or dark) set as active theme color in app code. According to the theme set as active, you can choose the corresponding images and graphic objects in your Windows Phone app pages.

Below app developers can find a few lines of C-Sharp code to test if Windows Phone Light theme is selected and set as active theme on target Windows Phone 8 device.

Visibility isVisible = (Visibility)Application.Current.Resources["PhoneLightThemeVisibility"];
if (isVisible == System.Windows.Visibility.Visible)
{
 // Active Windows Phone 8 Theme is Light Theme
 MessageBox.Show("Light");
} else {
 // Active Windows Phone 8 Theme is Dark Theme
 MessageBox.Show("Dark");
}
Code

And here is an other method in VB.NET code programmers can use in their Windows Phone app development projects to identify active Windows Phone theme color. The first two function codes return true if selected theme is selected in their theme colors. And the last code block calls these functions to detect active Windows Phone 8 theme.

Private Function LightThemeUsed() As Boolean
 Return CType(Application.Current.Resources("PhoneLightThemeVisibility"), Visibility) = System.Windows.Visibility.Visible
End Function

Private Function DarkThemeUsed() As Boolean
 Return CType(Application.Current.Resources("PhoneDarkThemeVisibility"), Visibility) = System.Windows.Visibility.Visible
End Function


Private Sub LoadImages()
 If LightThemeUsed() Then
 ' Light Theme is set as active Windows Phone 8 Theme
 End If
 If DarkThemeUsed() Then
 ' Dark Theme is set as active Windows Phone 8 Theme
 End If
End Sub
Code


Windows 10 Games

Microsoft Games on Windows 8 and Windows 10


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.