Is there a bug when changing themes when app is de

2020-02-11 07:16发布

问题:

Edit: This is under windows 7.1 RC. (This code did work for 7.0)

Lets say we open the application up in the dark theme. A line of code to detect this would be as follows:

    isDarkTheme = (Visibility.Visible == (Visibility)Application.Current.Resources[StringResource.PhoneDarkThemeVisbility]);

In this case, isDarkTheme will be true. Now hit the windows key, change your theme to light theme. and hit the back button to go back to your application. Run the following line of code again (in your activated event)

    isDarkTheme = (Visibility.Visible == (Visibility)Application.Current.Resources[StringResource.PhoneDarkThemeVisbility]);

Apparently isDarkTheme is still true even though we switched themes. Has anyone else ran into this problem or am I using an older way to check the current theme?

回答1:

This is a known issue. The theme is applied to your application when it starts, so only then you are able to correctly detect whether the light or dark setting is used. Otherwise, you are stuck with the old theme until the application restarts.

That being said, it is unlikely that the user will reproduce this behavior. If he switched from your app to phone settings, chances are he is not going back via the back button.