Detecting the Windows Phone Theme Background Color

Posted on

We often need to detect the WP background theme color to switch the color schemes of our apps.

This is very useful when we utilize the application bar and have some metro icons in our app. In built WP apps have this feature and switch between different icons. For example when you use the Messaging app in dark background mode the icons are white and when the background is in light mode. A very simple feature but how to detect the background theme color of the WP.

Here’s the code snippet for this. PhoneBackgroundBrush is a property of the Application.Current.Resources Dictionary object.

private readonly Color _lightThemeBackground = Color.FromArgb(255, 255, 255, 255); private readonly Color _darkThemeBackground = Color.FromArgb(255, 0, 0, 0); private void DetectPhoneTheme() { SolidColorBrush theme = Application.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush; if (theme.Color == _lightThemeBackground) { btnBack.IconUri = new Uri("Images/backB.png", UriKind.Relative); BtnNext.IconUri = new Uri("Images/nextB.png", UriKind.Relative); BtnShare.IconUri = new Uri("Images/shareB.png", UriKind.Relative); } else { btnBack.IconUri = new Uri("/Images/backW.png", UriKind.Relative); BtnNext.IconUri = new Uri("/Images/nextW.png", UriKind.Relative); BtnShare.IconUri = new Uri("/Images/shareW.png", UriKind.Relative); } } private readonly Color _lightThemeBackground = Color.FromArgb(255, 255, 255, 255); private readonly Color _darkThemeBackground = Color.FromArgb(255, 0, 0, 0); private void DetectPhoneTheme() { SolidColorBrush theme = Application.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush; if (theme.Color == _lightThemeBackground) { btnBack.IconUri = new Uri("Images/backB.png", UriKind.Relative); BtnNext.IconUri = new Uri("Images/nextB.png", UriKind.Relative); BtnShare.IconUri = new Uri("Images/shareB.png", UriKind.Relative); } else { btnBack.IconUri = new Uri("/Images/backW.png", UriKind.Relative); BtnNext.IconUri = new Uri("/Images/nextW.png", UriKind.Relative); BtnShare.IconUri = new Uri("/Images/shareW.png", UriKind.Relative); } }

Advertisements

One thought on “Detecting the Windows Phone Theme Background Color

    seo place said:
    March 2, 2013 at 3:19 AM

    Hey there! This is kind of off topic but I need some guidance from an established blog.
    Many thanks

Comments are closed.