Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when the theme is changed in WP7?

My app is fully theme aware. When my app is deactivated and user changes theme from dark to light (let's say) and returns to my application, the theme is not refreshed. Even though the phone theme is light my app still remains dark.

I did some tryings but they report the same values. I declared a variable called isDarkThemeSelected, saved the value in deactivated event, changed the theme, and entered back into my application. But when the activated event is raised the variable value still remain the same.

Do you have any solution?

like image 397
betim Avatar asked Nov 14 '11 21:11

betim


1 Answers

Add this code to your main page constructor:

var v = (Visibility)Resources["PhoneLightThemeVisibility"];
Debug.WriteLine("Using " + (v == Visibility.Visible ? "light" : "dark") + " theme");

(It detects the current theme and writes to the Output window which one it is.)

Then start the app, look at the Output in Visual Studio, close the app, change the theme, start the app and look again. If it says different things the first time and the second time then your app isn't as theme-aware as you think.

Edit: It seems like this doesn't always work due to a Mango bug. The theme remains the same when you navigate back to the app after changing the theme. It is only when the user restarts the app from the app list that the new theme is applied.

like image 113
Heinrich Ulbricht Avatar answered Oct 05 '22 23:10

Heinrich Ulbricht