user60456
user60456

Reputation:

How can I make the icons in the Application Bar change depending on the current theme?

In WP7 apps, what is the preferred way to make the icons in the Application Bar match the current theme (light/dark)? Do I really need to use the "hack" to detect the current theme, and set the icons based on that, or is there a better way?

Upvotes: 3

Views: 1163

Answers (3)

Rustem Bekmukhametov
Rustem Bekmukhametov

Reputation: 31

Just use PhoneDarkThemeVisibility resource:

<Image Source="pathToLightImage.png" Visibility="{StaticResource PhoneLightThemeVisibility}" />

<Image Source="pathToDarkImage.png" Visibility="{StaticResource PhoneDarkThemeVisibility}" />

Depending on user settings only one of two items will be displayed. It is available in Mango.

Another option is to use only one image with OpacityMask configured. You can find out more about it here.

Upvotes: 3

Edward
Edward

Reputation: 7424

I would suggest you store both sets of icons, dark and light, and create the app bar dynamically in the code behind. Then give the user the option to choose which theme they would like and handle the icons that get loaded using a simple if...else statement.

Now in order to determine which theme the user is using you can check the "phonelightthemevisibility" resource. Check if that resource is visible.

Visibility v = (Visibility)Resources["PhoneLightThemeVisibility"];
if(v = System.Windows.Visibility.Visible)
{
   //Use icons for light theme
}
else
{
   //Use icons for dark theme
}

Let me know if this helps.

Upvotes: 1

Derek Lakin
Derek Lakin

Reputation: 16319

If you use the default (white) images, or create similar PNG images that are white on transparent, then you don't need to do anything; the operating system handles it for you.

Upvotes: 8

Related Questions